Hello Reader!If you wish to add, delete or modify columns in an existing table you can do this with the help of ALTER command.
The syntax to change or we can say to modify a column in an existing table in SQL server is:
ALTER TABLE table-name
ALTER COLUMN column_name column_type;
Example:
ALTER TABLE employees
ALTER COLUMN first_name VARCHAR(40) NOT NULL;
Following example will modify the column first_name to be a datatype of VARCHAR(40) and will force a column to not allow null values.
The syntax to add new column in an existing table in SQL server is:
ALTER TABLE table-name
ADD column_name datatype;
Example:
ALTER TABLE employees
ADD department varchar(15);
Following example will add the column department to an existing table employee of datatype VARCHAR with size upto 15 characters.
0 Comment(s)