Forums » .NET » SQL Server »

WIll Primary key allow null?


Posted Date: 19 Aug 2008      Posted By:: Cathrin     Member Level: Gold    Member Rank: 0     Points: 1   Responses: 10



I created a table through Query where I set a particular column as PrimaryKey..It does not accept duplicate values when i try to insert them..However it accepts null..Will Primary key accept null values?



Responses

#282940    Author: Sivakumar Johnson      Member Level: Silver      Member Rank: 2484     Date: 19/Aug/2008   Rating: 2 out of 52 out of 5     Points: 0

never allows null

 
#282941    Author: Dharmaraj Nagarajan        Member Level: Gold      Member Rank: 18     Date: 19/Aug/2008   Rating: 2 out of 52 out of 5     Points: 2

HI,
Primary key will not allow the null values. If you want to allow null values you have to go for foriegn key.

All is well.
Thanks,
Dharma
Editor,Mentor,MVM
Try and fail but don't fail and try


 
#282943    Author: suresh kumar      Member Level: Bronze      Member Rank: 0     Date: 19/Aug/2008   Rating: 2 out of 52 out of 5     Points: 4

hi suresh here...
if u ve created primary key for a column it will not allow null values...if u tried to click allow nulls property in enterprise manager it shows the following error(allow nulls property can not beset on a column which is the part of the primary key)





 
#282944    Author: Cathrin      Member Level: Gold      Member Rank: 0     Date: 19/Aug/2008   Rating: 2 out of 52 out of 5     Points: 0

Then how did it allow null values?

 
#282985    Author: Reddy      Member Level: Silver      Member Rank: 2944     Date: 19/Aug/2008   Rating: 2 out of 52 out of 5     Points: 3

Primary key will not allow the null values
you are saying,ur created table with primary key allows null values na
please send ur crated table script


 
#283108    Author: Saurabh Hoonka      Member Level: Silver      Member Rank: 0     Date: 19/Aug/2008   Rating: 2 out of 52 out of 5     Points: 4

Hi Cathrin ,
look, a primary key means unique and not null. it means it would not allow either null value or not unique value. on the other hand a composite (but bot primary) or foreign key will accept a null or unique value. hope this informaion will help you.


 
#283119    Author: Sudha      Member Level: Silver      Member Rank: 0     Date: 19/Aug/2008   Rating: 2 out of 52 out of 5     Points: 3

The main advantage of the primary key is not allowing the null values into columns.It would be better if you provide more details like table format.So that we can give our look on that.

 
#283591    Author: Ultimaterengan      Member Level: Gold      Member Rank: 10     Date: 20/Aug/2008   Rating: 2 out of 52 out of 5     Points: 2

hi,

Primary key and unique key does not allow enter duplicate data.
Primary key and unique are Entity integrity constraints.unique key can be null but primariy key cant be null.
primariy key can be refrenced to other table as FK.We can declare only one primary key in a table but a table can have multiple unique key(column assign

i hope this may help u



Thanks & Regards
G.Renganathan
Nothing is mine ,Everything is yours!!!



 
#284378    Author: Sriram      Member Level: Gold      Member Rank: 0     Date: 21/Aug/2008   Rating: 2 out of 52 out of 5     Points: 1

Primary key wont allow null values and duplicate values

 
Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.



Next : how to get data to Excel
Previous : sql
Return to Discussion Forum
Post New Message
Category: SQL Server

Related Messages

Subscribe to Subscribers
Active Members
TodayLast 7 Daysmore...

Awards & Gifts
Talk to Webmaster Tony John
Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India