Collections:
"ALTER TABLE ... ALTER COLUMN" - Changing Column Data Type in SQL Server
How to change the data type of an existing column with "ALTER TABLE" statements in SQL Server?
✍: FYIcenter.com
Sometimes, you may need to change the data type of an existing column. For example, you want increase the string length of a column. You can use the "ALTER TABLE ... ALTER COLUMN" statements in the following syntax:
ALTER TABLE table_name ALTER COLUMN column_name new_type
Here is a good example of change column data types:
-- Can not make a string column shorter ALTER TABLE tip ALTER COLUMN subject VARCHAR(10) GO Msg 8152, Level 16, State 14, Line 1 String or binary data would be truncated. The statement has been terminated. -- Can make a string column longer ALTER TABLE tip ALTER COLUMN subject VARCHAR(100) GO Command(s) completed successfully. -- Can not change string to numeric ALTER TABLE tip ALTER COLUMN subject NUMBER GO Msg 8114, Level 16, State 5, Line 1 Error converting data type varchar to numeric. The statement has been terminated.
As you can see, the new date type must be compatible with the old data type in order for the "ALTER TABLE ... ALTER COLUMN" statement to work.
⇒ "sp_rename ... 'OBJECT'" - Renaming Existing Tables in SQL Server
⇐ Renaming an Existing Column with Management Studio in SQL Server
2016-11-15, 3482🔥, 0💬
Popular Posts:
What is SQL Server Transact-SQL (T-SQL)? SQL Server Transact-SQL, also called T-SQL, is an extension...
How to set the current database in SQL Server? Once you are connected to the SQL Server, you should ...
How To Enter Unicode Character String Literals in SQL Server Transact-SQL? Unicode characters are mu...
What is dba.FYIcenter.com Website about? dba.FYIcenter.com is a Website for DBAs (database administr...
What Is Oracle in Oracle? Oracle is a company. Oracle is also a database server, which manages data ...