Tuesday 20 December 2011

Explain NOT NULL constraint in SQL Server.

The NOT NULL constraint is used not to accept NULL values in a column. This makes sure to add values at the time of adding and updating the records.
Ex :
Create Table Suppliers
(
Supplier_ID int NOT NULL,
Supplier_Name varchar (300) NOT NULL,
Address varchar (500),
City varchar (200)
)
This Query will make sure the “Supplier_ID” and “Supplier_Name” columns to not accept NULL values.

Labels:


Bookmark this Blog in your Favorites

Thursday 1 December 2011

Explain the ALTER table statement in SQL Server.

The ALTER table statement is used to add, delete or modify the columns in a table.

Ex :
To ADD a column in a table,

ALTER TABLE Employees

ADD DateofBirth date

This Query will display a new column “DateofBirth” in date format to Employees table.

To DELETE a column in a table,

ALTER TABLE Employees

DROP column DateofBirth

This Query will delete the column “DateofBirth” from Employees table.

Labels:


Bookmark this Blog in your Favorites