aspx Tutorial

NET Articles,jQuery demo, asp.net with jQuery, online tutorial,Jquery, SilverLight, Javascript, asp.net,JSON, MVC,.NET Articles,demo, Web Services,
Advertise Here

Toolbar

Get our toolbar!

Advertize



Posted by Aamir Hasan   on Saturday, May 15, 2010 Total Views:  

Primary key:

uniquely identified each row in Table is called primary key. One table can have more then one primary key, primary key can not allow null values and duplicate value. it is default cluster indexes.

Unique key:

uniquely identified each row in Table is called uniquely key.Unique key does not allow duplicate values.Unique key allows only one null value in a column of table in which you have define unique key constraint.

I have created Student Table as shown below,

CREATE TABLE student

    (

      id INT NOT NULL ,

      fullName VARCHAR(100) NOT NULL ,

      gender CHAR(1)

    )

Insert some records into student table.

INSERT  INTO student

VALUES  ( 1, 'aamir hasan', 'M' )

INSERT  INTO student

VALUES  ( 1, 'aamir hasan', 'M' )

 

SELECT  *

FROM    Student

 

DELETE  FROM student


Define a primary key constraint on id field

ALTER TABLE student ADD CONSTRAINT pkstudent PRIMARY KEY (id)

Insert some records into student table.

INSERT  INTO student

VALUES  ( 1, 'aamir hasan', 'M' )

INSERT  INTO student

VALUES  ( 1, 'aamir hasan', 'M' )

DELETE FROM student

Add Unique Key contraint on fullname

ALTER TABLE student ADD CONSTRAINT IX_Name UNIQUE(fullName)

INSERT INTO student VALUES(1,null,'M')

INSERT INTO student VALUES(1,'null','M')

INSERT INTO student VALUES(1,'aamir hasan','M')

INSERT INTO student VALUES(1,'aamir hasan','M')

 

SELECT * FROM student

Protected by Copyscape Online Plagiarism Tool

Comments (1) -

Loren Vosburgh
Loren Vosburgh United States
6/28/2015 5:05:00 PM #

Hello there! I know this is kinda off topic nevertheless I'd figured I'd ask. Would you be interested in exchanging links or maybe guest authoring a blog article or vice-versa? My blog discusses a lot of the same topics as yours and I feel we could greatly benefit from each other. If you happen to be interested feel free to shoot me an e-mail. I look forward to hearing from you! Awesome blog by the way!|

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

Advertizement 1
Advertizement 2
Advertizement 3
Advertizement 4
Advertizement 5