Xpode.com        Click here to Print this article.

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)



http://


Contributed by:
Rohit kakria
I am software developer, moderator of xpode.com

Resourse address on xpode.com
http://www.xpode.com/Print.aspx?Articleid=73

Click here to go on website