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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 create cadidate key

Author  Topic 

putane.sanjay
Yak Posting Veteran

77 Posts

Posted - 2007-03-09 : 03:09:43
Hi
Iam learning tsql .HOW TO CREATE A CANDIDATE KEY, COMPOSITE KEYS ON A COLUMN IN A TABLE?

Please give me an example with the code .


snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2007-03-09 : 12:43:33
You don't create candidate keys, they are a logical concept. Any way that you can uniquely identify ever row in a table is a candidate key, there can be many and each one could be based on a single column or a group of columns (that's a composite key).

What's important is that you select one of the candidate keys as the key that you will use to uniquely identify every row in the table, and that is the primary key.

See the CREATE TABLE statement in Books Online for the syntax and code samples to create tables with a primary key.
Go to Top of Page

rlaubert
Yak Posting Veteran

96 Posts

Posted - 2007-03-09 : 13:10:13
A candidate key is any column in the table that you think may make a good index column. IE the column will be used in joins or the where clause.
Composite Keys are two or more columns that are used as part of an index. Normally composite keys are a good idea when the join or where clause has multiple column to check OR when the composite index 'satisfies' the query. For example, if you have a composite index that contains the first and last name fields and your select statement returns the first and last names, a composite index will be used by SQL to return the data rather than reading the data from the table itself. This reduces IO operations and can improve performance in some cases.

Raymond Laubert
MCDBA, MCITP:Administration, MCT
Go to Top of Page
   

- Advertisement -