开发者

Query in SQL2000

How to alter 开发者_Go百科the datatype of a column in a table?


CREATE TABLE dbo.MyTable (column_a INT );
GO
INSERT INTO dbo.MyTable  (column_a) VALUES (10);
GO
ALTER TABLE dbo.MyTable  ALTER COLUMN column_a DECIMAL (5, 2);
GO
DROP TABLE dbo.MyTable;
GO


alter table yourtable alter column yourcolumnname yourdatatype;

This only works if SQL can cast the old values to the new values with the new datatype. If this fails, you will have to create a new column, migrate the data some way, and drop the old column.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜