mardi 30 juin 2015

Wich of these is the right way to do foreign keys?

So, i'm trying sqlite3 and i have a question about Foreign Keys and Indices.

Wich of these methods is the right one ?

CREATE TABLE artist(
  artistid    INTEGER PRIMARY KEY, 
  artistname  TEXT
);
CREATE TABLE track(
  trackid     INTEGER,
  trackname   TEXT, 
  trackartist INTEGER REFERENCES artist
);
CREATE INDEX trackindex ON track(trackartist);

OR this one:

CREATE TABLE student(
  SudentID INTEGER PRIMARY KEY,
  First TEXT,
  Last,
  Contact Text,
  Year INTEGER)

CREATE TABLE loan(
  StudentID INTEGER,
  ISBN INTEGER,
  out INTEGER,
  FOREIGN KEY(SudentID)
      REFERENCES student(SudentID)
      ON DELETE CASCADE
  PRIMARY KEY(StudentID, ISBN)
)
CREATE INDEX StudentID_Index ON student(StudentID)

Aucun commentaire:

Enregistrer un commentaire