You are here: Re: Primary Key with two columns « MsSQL Server « IT news, forums, messages
Re: Primary Key with two columns

Posted by David Portas on 12/19/07 11:49

"YZXIA" <yzx27@hotmail.com> wrote in message
news:acf22b78-2cf5-4aea-823d-9f718577de64@w40g2000hsb.googlegroups.com...
>I need to make a primary key, which constitute two different columns
> on our MS SQL server. When I wrote the following code I received an
> error message:
>
>
> create table t_dz_borrowing_record
> (
> CutOffDate datetime not null Primary key,
> LoanType varchar(20) not null primary key,
> ..... More columns
> )
>
>
> Msg 8110, Level 16, State 0, Line 2
> Cannot add multiple PRIMARY KEY constraints to table
> 't_dz_borrowing_record'.
>
> Does anyone know how to make a primary key which is a combination of
> two columns?


Books Online is your friend. Get to know it.

You should name your constraints so I've added the CONSTRAINT clause and a
name as well:

CREATE TABLE t_dz_borrowing_record
(
CutOffDate datetime not null,
LoanType varchar(20) not null,
CONSTRAINT t_dz_borrowing_record_pk PRIMARY KEY (CutOffDate, LoanType),
..... More columns
);

--
David Portas

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация