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, Building Your First Web Application Project
Advertise Here

Toolbar

Get our toolbar!

Advertize



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

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

Advertizement 1
Advertizement 2
Advertizement 3
Advertizement 4
Advertizement 5