Here are examples of several CREATE TABLE commands:
CREATE TABLE Student
( Sname VarChar(25) Not Null,
Dorm VarChar(20) Not Null,
Room Integer,
Phone Char(12),
Major VarChar(20),
MajorAdvisorName VarChar(25),
CONSTRAINT StudentPK PRIMARY KEY( Sname, Dorm ),
CONSTRAINT StudentDormFK FOREIGN KEY( DORM )
REFERENCES Dorm( Dorm ),
CONSTRAINT StudentFacultyFK FOREIGN KEY( MajorAdvisorName )
REFERENCES Faculty( Fname )
);
CREATE TABLE Dorm
( Dorm VarChar(20) Not Null,
RA VarChar(25),
CONSTRAINT DormPK PRIMARY KEY( Dorm )
);
CREATE TABLE Faculty
( Fname VarChar(25) Not Null,
Dept VarChar(20),
CONSTRAINT FacultyPK PRIMARY KEY( Fname )
);
Another kind of constraint is the CHECK constraint. A CHECK constraint allows one to specify valid
conditions for a column. For instance:
CONSTRAINT FoundedCheck CHECK ( FoundedDate > 1900),
CONSTRAINT ZipCheck CHECK ( zip LIKE '[0-9][0-9][0-9][0-9][0-9]' ),
The first constraint will insure that the column FoundedDate has a value more recent than 1900, and the
second will insure that the column zip will consist of five numeric characters. In the case of the second CHECK
constraint, the syntax says that zip must be ???like??? five characters, each of which is a numeric character
between 0 and 9.
Pages:
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416