February 25, 2002 at 11:05 am
In Access it's possible to apply two primary keys to a field (so that both fields must be unique as a pair)--will SQL Server 2000 recognize such structures? How would this be accomplished?
February 25, 2002 at 11:19 am
In SQL this would be a compound PK. You could setup two fields as the PK with
ALTER TABLE dbo.<xxx, char( 32), TblName> ADD CONSTRAINT
Table_PK PRIMARY KEY NONCLUSTERED
(
FieldA Int
, FieldB int)
Steve Jones
February 25, 2002 at 11:22 am
Composite keys (when multiple fields make up a unique identifier for a row) are supported in SQL Server. A way to do this in T-SQL is to use a table-level constraint. Instead of creating the constraint against the column like so:
Table Example (
ColumnName int NOT NULL CONSTRAINT PK_Example PRIMARY KEY,
.
.
.
)
we would create a constraint separate from the column like so:
CREATE TABLE Example (
Column1 char(3) NOT NULL,
Column2 int NOT NULL,
.
.
.
CONSTRAINT PK_Example PRIMARY KEY (Column1, Column2)
)
K. Brian Kelley
http://www.sqlservercentral.com/columnists/bkelley/
K. Brian Kelley
@kbriankelley
February 25, 2002 at 11:24 am
Or in EM click the first items row selector (the grey box to the side) and then hold down shift or ctrl to select others the same way and finally press the PrimaryKey button or right click and choose Primary Key. Then save.
"Don't roll your eyes at me. I will tape them in place." (Teacher on Boston Public)
February 25, 2002 at 11:28 am
thanks everybody!
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply