July 3, 2013 at 3:55 am
Hi,
I have doubts multiple primay key on single table,
Table can be support multiple primary key in this case one Clustred index created by default and other primary key which index name will be created?
thanks
ananda
July 3, 2013 at 4:18 am
A table can only have a single clustered index and a single primary key. However these do not have to be the same; you could have a non clustered primary key and a seperate clustered index if that suited your needs.
In addition, you can have unique indexes; bear in mind that they will allow NULL values whereas a primary key will not.
Follow me on twitter @EvoDBACheck out my blog Natural Selection DBA[/url]
July 3, 2013 at 4:46 am
I have tested multiple primary key in single table.
PK - columname 1 - [id_no]
PK - columname 2 - [id_nos]
ALTER TABLE [dbo].[Index_testing] ADD CONSTRAINT [PK_Index_testing] PRIMARY KEY CLUSTERED
(
[id_no] ASC,
[id_nos] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
the above statement one clustred index have two Primarykey and two different column name..so it is treated as composite primary key..
July 3, 2013 at 4:52 am
That's not two primary keys. It's one primary key constraint over two columns - a composite key.
John
July 3, 2013 at 4:58 am
thank you Mr. Johan,
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply