PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Hébergement serveur > comp.db.ms-sqlserver > Primary Key with two columns
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Primary Key with two columns

Réponse
 
LinkBack Outils de la discussion
Vieux 19/12/2007, 00h57   #1
YZXIA
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Primary Key with two columns

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?
  Réponse avec citation
Vieux 19/12/2007, 04h01   #2
Tom van Stiphout
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Primary Key with two columns

On Tue, 18 Dec 2007 15:57:51 -0800 (PST), YZXIA <yzx27@hotmail.com>
wrote:

From Books online, on the topic of Create Table:
CREATE TABLE [dbo].[PurchaseOrderDetail]
(
[PurchaseOrderID] [int] NOT NULL
REFERENCES Purchasing.PurchaseOrderHeader(PurchaseOrderID),
[LineNumber] [smallint] NOT NULL,
[ProductID] [int] NULL
REFERENCES Production.Product(ProductID),
[UnitPrice] [money] NULL,
[OrderQty] [smallint] NULL,
[ReceivedQty] [float] NULL,
[RejectedQty] [float] NULL,
[DueDate] [datetime] NULL,
[rowguid] [uniqueidentifier] ROWGUIDCOL NOT NULL
CONSTRAINT [DF_PurchaseOrderDetail_rowguid] DEFAULT (newid()),
[ModifiedDate] [datetime] NOT NULL
CONSTRAINT [DF_PurchaseOrderDetail_ModifiedDate] DEFAULT
(getdate()),
[LineTotal] AS (([UnitPrice]*[OrderQty])),
[StockedQty] AS (([ReceivedQty]-[RejectedQty])),
CONSTRAINT [PK_PurchaseOrderDetail_PurchaseOrderID_LineNumber]
PRIMARY KEY CLUSTERED ([PurchaseOrderID], [LineNumber])
WITH (IGNORE_DUP_KEY = OFF)
)
ON [PRIMARY]

-Tom.



>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?

  Réponse avec citation
Vieux 19/12/2007, 12h49   #3
David Portas
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Primary Key with two columns

"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


  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 01h56.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,08932 seconds with 11 queries