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

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

Advertizement 1
Advertizement 2
Advertizement 3
Advertizement 4
Advertizement 5