Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 pls help

Author  Topic 

suneil23
Starting Member

4 Posts

Posted - 2006-07-03 : 01:31:24
please tell me what is the point in using this "constraint PK_Customers PRIMARY KEY CLUSTERED CustomerID)"in the below mentioned query

create table customers(customerID int not null,customername char(10) not null,country char(20) null,constraint PK_Customers PRIMARY KEY CLUSTERED CustomerID));

insert into customers values(1001,'Ram','India');
insert into customers values(1002,'Sam','USA');
insert into customers values(1003,'Tom','UK');
insert into customers values(1004,'Pam','Australia');
insert into customers values(1005,'Van','USA');
insert into customers values(1006,'Mam','UK');
insert into customers values(1007,'Kim','USA');
insert into customers values(1008,'Kin','China');
insert into customers values(1009,'Pin','China');
insert into customers values(1010,'Min','Japan');

select *from customers;

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-07-03 : 01:59:44
To make CustomerID as primary key with constraint name PK_Customers
Read about Create table in sql server help file for more information

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2006-07-03 : 02:53:53
no benefit, coz it'll still do a scan on the table
show the execution plan when you run the query and you'll get the info you need

--------------------
keeping it simple...
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-07-03 : 03:09:21
If you want to select all rows and still want to make use of Index then use where clause

select *from customers where customerID>0

provided that it is always more than 0


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

mr_mist
Grunnio

1870 Posts

Posted - 2006-07-03 : 04:10:45
It will do a scan with that SELECT * FROM yourtable, but one benefit is that the PRIMARY KEY constraint will enforce integrity on the customer ID, meaning that you won't get duplicates in your database.


-------
Moo. :)
Go to Top of Page
   

- Advertisement -