Re: One column is nullable on the composite key
From: Erland Sommarskog (esquel_at_sommarskog.se)
Date: 08/14/04
- Next message: Adam Machanic: "Re: Query Designer Error message - for UPDATE sequence"
- Previous message: Gerald S: "Re: SQL Select Query Help"
- In reply to: Andy: "One column is nullable on the composite key"
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 14 Aug 2004 22:11:02 +0000 (UTC)
Andy (net__space@hotmail.com) writes:
> I would like to have a composite PK on 3 columns, one of them is null
>
>
> CREATE TABLE TableA (
> ColA int NOT NULL ,
> ColB int NOT NULL ,
> ColC char (3) NULL ,
> ......
> )
> GO
All columns in a primary key must be NOT NULL. This is a basic concept
in relational databases.
However, you can define a UNIQUE constraint on the columns. SQL Server will
then allow exactly one row with NULL in ColC for any given value of ColA and
ColB.
If you have references to this table, you should probably throw in a
surrogate key, and use that as foreign key to other tables.
-- Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se Books Online for SQL Server SP3 at http://www.microsoft.com/sql/techinfo/productdoc/2000/books.asp
- Next message: Adam Machanic: "Re: Query Designer Error message - for UPDATE sequence"
- Previous message: Gerald S: "Re: SQL Select Query Help"
- In reply to: Andy: "One column is nullable on the composite key"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|