Gabriel Matusevich
Gabriel Matusevich

Reputation: 3855

SQL SERVER FK and Constraint

I'm working with SQL SERVER 2000 and I have this code for creating a table. My table has foreign keys and I wish to add a constraint. My Question is: Must I define the constraint AND the foreign key? or is just one of them enough?

CREATE TABLE controls
(
id                  INT         IDENTITY(1,1)   PRIMARY KEY,
description         VARCHAR(2000),
date                DATETIME,
result              VARCHAR(255),
clients_id          INT FOREIGN KEY REFERENCES clients(id),
profesionals_id     INT FOREIGN KEY REFERENCES profesionals(id),
CONSTRAINT FK_CLIENTS   FOREIGN KEY (clients_id) REFERENCES clients(id)
);

The last 2 lines, FK definition and Constraint, is it redundant?

Upvotes: 1

Views: 78

Answers (1)

Mureinik
Mureinik

Reputation: 312267

The last line

CONSTRAINT FK_CLIENTS   FOREIGN KEY (clients_id) REFERENCES clients(id)

Is equivalent to the iniline definition following client_ids:

FOREIGN KEY REFERENCES clients(id)

One of the two should be removed.

Upvotes: 2

Related Questions