Is it possible to alter a SQL Server table column datatype from bigint to varchar after it has been populated?
I have a SQL Server 2008 table which contains an external user reference currently stored as a bigint - the userid from the external table. I want to extend this to allow email address, open ID etc to be used as the external identifier. Is it possible to alter the column datatype from bigint to varchar without affecting any of the existing d开发者_开发知识库ata?
Yes, that should be possible, no problem - as long as you make your VARCHAR
field big enough to hold you BIGINT values :-)
You'd have to use something like this T-SQL:
ALTER TABLE dbo.YourTable
ALTER COLUMN YourColumnName VARCHAR(50) -- or whatever you want
and that should be it! Since all BIGINT
values can be converted into a string, that command should work just fine and without any danger of losing data.
精彩评论