Reputation: 4718
I have a SQL server database design problem.
I have an existing database table with hundreds of records in there. One of the columns is of type NVARCHAR but it should be an integer with all the data in a lookup table.
Is there any clever way in SQL Server to get the data out of the column and into a new lookup table, change the datatype of the column and update the values with the correct ID from the new lookup table??
Thanks in advance.
I'm using SQL Server 2008
Upvotes: 0
Views: 606
Reputation: 239714
No, you have to do it as 3 steps:
nvarchar
column now contains appropriate ID values from the lookup tableint
Thankfully, int
values should always be able to fit in an nvarchar
, unless it's an especially small one (in which case you'll have to expand it first).
Upvotes: 3