Sunday, 6 December 2015

How to modify the table structure in SQL Server

Once the table is created in SQL Server, you can modify the table structure either through GUI or through script. I am going to list down the possible cases of updating the table structure

Add a column:

ALTER TABLE "TABLE-NAME" ADD "COLUMN-NAME" varchar(50) NULL

Modify the Data Type:

ALTER TABLE "TABLE-NAME" ALTER COLUMN "COLUMN-NAME" "NEW DATA TYPE" NULL

Modify the NOT-NULL Constraint:

ALTER TABLE "TABLE-NAME" ALTER COLUMN "COLUMN-NAME" VARCHAR(30) NOT NULL

No comments:

Post a Comment