C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !






Constraints in Sql server - part -1


Posted Date: 22 Aug 2008    Resource Type: Articles    Category: Databases

Posted By: D.Jeya kumar(JK)       Member Level: Diamond
Rating:     Points: 10



Constraints in Sqlserver:
Constraints are to check the type of data is consistent for the field when inserted or modified. It is used to enforce Data integrity. It allows you to have the consistent and accurate values in a Database

Types of constraints are broadly classified in sqlserver are

Primary Key constraint
Unique Key constraint
Foreign Key constraint
Check constraint
Primary Key constraint:
Primary key will check and it will not allow the Duplicate values and null values for the specified field. A Table can have only one primary key. A primary key can be created on the creation of the table or later also we can modify the table

Syntax for Primary Key

Create table <Table_Name> ( <Column_name1> <Data_type1> IDENTITY(1,1) NOT NULL PRIMARY KEY, <Column_name2> <Data_type2>, <Column_name3> <Data_type3> etc.,)
Once the table is create we can alter the table

Alter table <Table_name> Add constraint <Constraint_name> Primary Key(Column_name)

Unique Key

Unique Key will not allow the Duplicate values and it will allow the null values. There can be any number of Unique key. Creating a primary key will automatically create a unique key.

Syntax

Create table <Table_Name> ( <Column_name> <Data_type> NOT NULL Unique, <Column_name2> <Data_type2>, <Column_name3> <Data_type3> etc.,)

Once the table is create we can alter the table

Alter table <Table_name> Add constraint <Constraint_name> Unique(Column_name)






Responses

Author: Sriram    02 Nov 2008Member Level: Gold   Points : 1
u r explain only primary key and unique what about remaining i meen
check,foreign key.


sriramRamaswamy


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Type of constraints  .  Constraints in Sql server  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: ACID Properties
Previous Resource: Fetching Data From SQL Linked server
Return to Discussion Resource Index
Post New Resource
Category: Databases


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

fax server

Contact Us    Privacy Policy    Terms Of Use