I am trying to change a column from a varchar(50)
to a nvarchar(200)
. What is the SQL command to alter this table?
We can use ALTER TABLE ALTER COLUMN statement to change the datatype of the column. The syntax to change the datatype of the column is the following. In the syntax, Tbl_name: Specify the table name that contains the column that you want to change.
So to do that go to SQL Server and within Tools select Options. Now in the option window expand Designers and under that "Table and Database Designers" and uncheck the check box "Prevent saving changes that require table re-creation" then click OK.
The ALTER COLUMN command is used to change the data type of a column in a table.
ALTER TABLE TableName ALTER COLUMN ColumnName NVARCHAR(200) [NULL | NOT NULL]
EDIT As noted NULL/NOT NULL should have been specified, see Rob's answer as well.
Don't forget nullability.
ALTER TABLE <schemaName>.<tableName> ALTER COLUMN <columnName> nvarchar(200) [NULL|NOT NULL]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With