cam
cam

Reputation: 9033

Altering a Table Column to Accept More Characters

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

Answers (5)

Rossi Alex
Rossi Alex

Reputation: 141

It is quite simple:

ALTER TABLE <table_name> MODIFY <column_name> VARCHAR(100)

Upvotes: 0

Justin
Justin

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

Roland Bouman
Roland Bouman

Reputation: 31951

ALTER TABLE tab ALTER COLUMN c VARCHAR(200)

Upvotes: 1

Randy Minder
Randy Minder

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

Joe
Joe

Reputation: 42577

ALTER TABLE [table] ALTER COLUMN [column] NVARCHAR(newsize)

And increasing the size won't affect your data.

Upvotes: 11

Related Questions