Reputation: 9033
What would the command be for Microsoft SQL Server 2008 to alter an existing column to allow for more characters? Would this have an effect on any previous entries in the column if I'm only expanding it?
I have a URL column that I need to add about 100 characters to.
Upvotes: 5
Views: 13952
Reputation: 141
It is quite simple:
ALTER TABLE <table_name> MODIFY <column_name> VARCHAR(100)
Upvotes: 0
Reputation: 86729
You can use SQL Server Management Studio to generate the code to do this yourself. Just modify the table in the designer so that the column is wider and click "Generate change script" (under the "Table designer" menu).
Depending on the change you make the code to modify a table can be fairly complex.
Upvotes: 0
Reputation: 48392
ALTER TABLE myTable ALTER COLUMN myColumn varchar(100)
GO
This would not involve the risk of losing data, because you are expanding the size of the column.
Upvotes: 2
Reputation: 42577
ALTER TABLE [table] ALTER COLUMN [column] NVARCHAR(newsize)
And increasing the size won't affect your data.
Upvotes: 11