Click here to hide categories Click here to show left categories

User: Home          welcome : Guest          Log In / Register here     




Add a column and set primary key in a table through query

In many situations we need to modify the table definition in database. I am showing how to add a Column to a Table.

Syntax: ALTER TABLE TableName add columnName DataType NULL/NOT NULL

Example: ALTER TABLE Employee add usercategory varchar(50) NULL

in code we are adding a new column usercategory table. Now we are adding a primary key in table.

Syntax: ALTER TABLE TableName add PRIMARY KEY(ColumnName)

Example: ALTER TABLE AddressType add PRIMARY KEY(AddressTypeID)

Share this article   |    Print    |    Article read by 1466 times
Author:
Rohit kakria
I am software developer, moderator of xpode.com
Related Articles:
Related Interview Questions: