aspx Tutorial

.NET Articles,jQuery demo, asp.net with jQuery, online tutorial,Jquery, SilverLight, Javascript, asp.net,JSON, MVC,.NET Articles,demo, Web Services, .NET articles, Sharepoint 2010, visual studio 2010,Aamir Hasan,IT
Advertise Here

Advertize

wwwSW
Posted by Aamir Hasan   on Thursday, December 30, 2010 Total Views:  

A unique identity in each row in a table is called Primary key. Primary key does not allowed null values and duplicate values. If table have duplicate values and you are applying primary key, it will return you an error message. You can modify and delete the primary key. You cannot change the data type of a column if primary key constraint exists.

Here’s is a query.


SELECT  TC.TABLE_NAME AS [TABLE name] ,

        CCU.COLUMN_NAME AS [column name] ,

        TC.CONSTRAINT_NAME [constraint name]

FROM    INFORMATION_SCHEMA.TABLE_CONSTRAINTS TC

        INNER JOIN INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE CCU

        ON Tc.CONSTRAINT_NAME = CCU.CONSTRAINT_NAME

        AND TC.CONSTRAINT_TYPE = 'PRIMARY KEY'

 

Advantage

  1. There is no chance of duplicate values.
  2. Primary key column can not contain null value.
  3. Other candidate keys are functionally dependent because of primary key constraint.
  4. It is easy to update a record.

4.     

Disadvantage

  1. There is chance of problem in merge replication.
  2. When then table is full scan it sort the table make the query slow.

 

Note: If you have null or duplicate values in the existing table and you are trying to create a primary key constraint, it will always return you error message as shown below.


Msg 8111, Level 16, State 1, Line 1
Cannot define PRIMARY KEY constraint on nullable column in table '[TABLE NAME]'.
Msg 1750, Level 16, State 0, Line 1

Could not create constraint. See previous errors.


Protected by Copyscape Online Plagiarism Tool

Comments (11) -

Aamir Hasan
Aamir Hasan
12/30/2010 5:31:31 AM #

Find primary key of the given table query.

SELECT  TC.TABLE_NAME AS [TABLE name] ,
        CCU.COLUMN_NAME AS [column name] ,
        TC.CONSTRAINT_NAME [constraint name]
FROM    INFORMATION_SCHEMA.TABLE_CONSTRAINTS TC
        INNER JOIN INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE CCU
        ON Tc.CONSTRAINT_NAME = CCU.CONSTRAINT_NAME
        AND TC.CONSTRAINT_TYPE = 'PRIMARY KEY'
        AND TC.TABLE_NAME ='[TABLE NAME]'


Mahwish Akhtar
Mahwish Akhtar People's Republic of China
12/30/2010 12:25:36 PM #

I have been looking around #hostname and really am impressed by the great content material here. I've been coming here for the previous couple nights and reading. I simply needed to let you know that I've been enjoying what I have seen and I look forward to reading more.Thanks

wholesale usb flash drives
wholesale usb flash drives United States
1/6/2011 6:27:49 PM #

I was wondering what is up with that weird gravatar??? I know 5am is early and I'm not looking my best at that hour, but I hope I don't look like this! I might however make that face if I'm asked to do 100 pushups. lol

how to get abs
how to get abs United States
2/28/2011 11:40:25 PM #


Wonderful men/women  come with  good gift and I essentialy enounce that the webmaster of this special blog is real talented and a  fabulous person too. I  do in truth appreciate the tough work  which had been completed on this web , from my deep heart. Me and my  spouse both are making a  college project on this subject and pictures n content both are very helpful to  build our project more and more powerful . Congratulations for  all work and  continue the appriciated work up with my wishes .

Manish
Manish India
4/12/2011 4:34:09 PM #

Hi I have lot of Duplicate Records in auto identity fields and it still generating new duplicate id's.

penis enlargement
penis enlargement United States
10/24/2011 4:49:06 AM #

great post.. i really enjoyed it

Android Training In Indore
Android Training In Indore United States
11/4/2011 8:13:25 PM #

I wanted to thank you for this great read!! I definitely enjoying this post and I have you bookmarked to check out new stuff you post.

Web Hosting company India
Web Hosting company India United States
11/4/2011 9:49:13 PM #

Wonderful post - I was looking for a similar article. Thanks for sharing this article to your reader. You give very nice information about

iit preparation
iit preparation United States
11/4/2011 10:08:56 PM #

I enjoy you because of Thank you for all of the every one of your effort hard work on this site.

adidas f50
adidas f50
2/29/2012 3:17:53 PM #

I long to alleviate the evil, but I cannot, and I too suffer. cheap soccer shoes has been my life. I have found it worth living, and would gladly live it again if the chance were offered me. http://www.ussoccercleat.com/ CF

five fingers shoes
five fingers shoes People's Republic of China
3/27/2012 12:05:12 AM #

GH-Among the vibram five finger, quilted jackets seem to be hogging the limelight at the moment. The skechers shape ups is known for its quality, practicality and style - five fingers vibram quilts give it good insulation for the colder months. skechers shape ups uk come in a variety of colours and styles, some will have http://www.vibram-five-finger.org/ contemporary chest pockets and others have vibram fingers slightly lower down (they usually have extra padding to keep your hands warm during winter). Some of the skechers uk have cord collars to contrast with the Vibram Five Fingers Classic, and all of the jackets have a fully-quilted polyamide lining and Skechers Boiling Point Boots insulation. http://www.skecher-uk.com/

fddf
fddf People's Republic of China
3/31/2012 10:05:11 PM #

http://burberryoutlet-burberryscarf.com

fafafa
fafafa Slovenia
4/23/2012 3:01:47 AM #

http://www.christianlouboutinukk.org   christian louboutin
http://www.tiffanyuks.org   tiffany uk
http://www.gucciukbeltuk.org   gucci belt
http://www.frsaclouisvuittonsac.com   louis vuitton sac
http://www.chanelukoutletuks.org   chanel outlet
http://www.burberryukoutletuk.org   burberry
http://www.poloralphlaurenuko.org   ralph lauren uk

Pingbacks and trackbacks (1)+

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

Advertizement 1
Advertizement 2
Advertizement 3
Advertizement 4
Advertizement 5