Question

Somebody created a column in our database where, originally, only 10-digit phone numbers were allowable (thus, the datatype CHAR(10) was used).

We're now trying to change the database to allow for something our system wasn't built to handle - international numbers with a variable length of phone number.

Originally, this database was ONLY handling PBX requests which passed NANP numbers ONLY (all international numbers were translated to a termination number before reaching the platform). Now there are going to be web requests that show the pre-translation number and we don't have the resources (time/staff) to do what we want, which would be creating a new table to handle the front end, then creating a relationship in the back end table.

Our database is replicated to three other servers (one on-site and two off-site on a VPN) and in the past this has sometimes caused a problem for us (So I'm told). Also, ALL values are currently 10 digit numbers, and there are ~100,000 records in the table. And to reiterate, we're using SQL Server (I believe 2008).

Are we able to change this datatype to a VARCHAR or INT value with an ALTER statement WITHOUT LOSING DATA, and secondarily, are we able to do this without turning off replication?

Additionally, would the correct code be one of the following two SQL commands, where the column name is DNIS?

ALTER DNISConfig
ALTER COLUMN [DNIS] VARCHAR(50)

or

ALTER DNISConfig
ALTER COLUMN [DNIS] INT
Était-ce utile?

La solution

You are correct:

ALTER TABLE DNISConfig  
 ALTER COLUMN [DNIS]  VARCHAR(50) NOT NULL

Will change the column to a VARCHAR.

My opinion, phone numbers are not INTs, so the VARCHAR option would be preferable.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top