How do you change the datatype of a column in SQL Server?

后端 未结 8 774
日久生厌
日久生厌 2020-11-29 16:19

I am trying to change a column from a varchar(50) to a nvarchar(200). What is the SQL command to alter this table?

8条回答
  •  臣服心动
    2020-11-29 17:15

    For changing data type

    alter table table_name 
    alter column column_name datatype [NULL|NOT NULL]
    

    For changing Primary key

    ALTER TABLE table_name  
    ADD CONSTRAINT PK_MyTable PRIMARY KEY (column_name)
    

提交回复
热议问题