1 / 3

More SQL – Specifying Foreign Keys

STUDENTS. More SQL – Specifying Foreign Keys. Consider the following tables, STUDENTS & GRADES. GRADES. Specifying Foreign Keys….

Download Presentation

More SQL – Specifying Foreign Keys

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. STUDENTS More SQL – Specifying Foreign Keys Consider the following tables, STUDENTS & GRADES GRADES CSE470 Software Engineering Fall 2000

  2. Specifying Foreign Keys… • The table GRADES has a foreign-key relationship with table STUDENTS, i.e., for every value of STU_ID in GRADES there must be a record with a matching ID in STUDENTS • The SQL statements to create the two tables will be as follows: • SQL to create table STUDENTS: CREATE TABLE STUDENTS ( ID INTEGER, NAME CHAR(30), DOJ DATETIME, EMAIL CHAR(30), CONSTRAINT PK_STUDENTS PRIMARY KEY (ID)) CSE470 Software Engineering Fall 2000

  3. Specifying Foreign Keys… • SQL to create table GRADES, with foreign key CREATE TABLE GRADES ( STU_ID INTEGER, COURSE CHAR(6), GRADE DECIMAL(2,1), CONSTRAINT PK_GRADES PRIMARY KEY (STU_ID, COURSE), CONSTRAINT FK_GRADES FOREIGN KEY (STU_ID) REFERENCES STUDENTS) CSE470 Software Engineering Fall 2000

More Related