Query in SQL2000

杀马特。学长 韩版系。学妹 提交于 2019-12-13 08:53:47

问题


How to alter the datatype of a column in a table?


回答1:


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



回答2:


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.



来源:https://stackoverflow.com/questions/2690403/query-in-sql2000

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!