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
 creating index on table...

Author  Topic 

raaj
Posting Yak Master

129 Posts

Posted - 2008-01-22 : 15:04:04
Hi
i am new to using this sql server 2000....this is a very simple question to all u guys.....i am just in a learning stage...so any help from u guys is really appreciable....

i need to create a table customers with the following columns...
identity column to self-populate as the primary key,
joindate, leavedate, custcode, empID.

This is the one i tried:
create table customers (id int primary key identity (1,1) not null,
joindate smalldatetime null,
leavedate smalldatetime null,
custcode varchar (10) not null,
empid int not null
)
is tht code correct only???
and i also want the below one :
Create indexes on the leavedate, custcode and empid columns.

how to create these indexes???
and wht happens when i create them(like is thr any advantage of creating indexes???)

thanks......


rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2008-01-22 : 23:24:20
Books online has sample code, just search 'create index'.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-01-22 : 23:30:45
You need to decide which column you must select for clustered index and which for nonclustered. Clustered index literally reorders the table by that column value.You can have only 1 clustered index and any number of non clustered ones. the syntax is

CREATE [CLUSTERED/NONCLUSTERED] INDEX IndexName ON customers(column(s))
Go to Top of Page
   

- Advertisement -