Sajmon

create

Mar 24th, 2012
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 3.02 KB | None | 0 0
  1.  
  2. CREATE TABLE Reservation
  3.     (
  4.      coachNumber INTEGER NOT NULL ,
  5.      seatNumber INTEGER NOT NULL ,
  6.      reservationDate DATETIME NOT NULL ,
  7.      paidDate DATETIME ,
  8.      canceledDate DATETIME ,
  9.      idTrainRide INTEGER NOT NULL ,
  10.      idUser INTEGER ,
  11.      CONSTRAINT Reservation_PK PRIMARY KEY NONCLUSTERED (coachNumber, seatNumber, idTrainRide)
  12.     )
  13. GO
  14.  
  15. CREATE TABLE Staff
  16.     (
  17.      idStaff INTEGER NOT NULL ,
  18.      fname VARCHAR (30) NOT NULL ,
  19.      lname VARCHAR (30) NOT NULL ,
  20.      position CHAR (1) NOT NULL ,
  21.      jobStart DATETIME NOT NULL ,
  22.      jobEnd DATETIME ,
  23.      salary INTEGER NOT NULL ,
  24.      CONSTRAINT Staff_PK PRIMARY KEY NONCLUSTERED (idStaff)
  25.     )
  26. GO    
  27.  
  28. CREATE TABLE Station
  29.     (
  30.      idStation INTEGER NOT NULL ,
  31.      name VARCHAR (60) NOT NULL ,
  32.      CONSTRAINT Station_PK PRIMARY KEY NONCLUSTERED (idStation)
  33.     )
  34. GO
  35.  
  36. CREATE TABLE Train
  37.     (
  38.      idTrain INTEGER NOT NULL ,
  39.      name VARCHAR (20) NOT NULL ,
  40.      coachCount INTEGER NOT NULL ,
  41.      price FLOAT NOT NULL ,
  42.      startTime TIME NOT NULL ,
  43.      endTime TIME NOT NULL ,
  44.      idStation INTEGER ,
  45.      idStation1 INTEGER ,
  46.      CONSTRAINT Train_PK PRIMARY KEY NONCLUSTERED (idTrain)
  47.     )
  48. GO
  49.  
  50.  
  51. CREATE TABLE TrainCrew
  52.     (
  53.      idStaff INTEGER NOT NULL ,
  54.      idTrainRide INTEGER NOT NULL ,
  55.      CONSTRAINT PK_TrainCrew PRIMARY KEY NONCLUSTERED (idStaff, idTrainRide)
  56.     )
  57. GO
  58.  
  59.  
  60. CREATE TABLE TrainRide
  61.     (
  62.      idTrainRide INTEGER NOT NULL ,
  63.      rideDate DATE NOT NULL ,
  64.      idTrain INTEGER ,
  65.      CONSTRAINT TrainRide_PK PRIMARY KEY NONCLUSTERED (idTrainRide)
  66.     )
  67. GO
  68.  
  69.  
  70. CREATE TABLE [User]
  71.     (
  72.      idUser INTEGER NOT NULL ,
  73.      email VARCHAR (30) NOT NULL ,
  74.      fname VARCHAR (40) ,
  75.      lname VARCHAR (40) ,
  76.      password VARCHAR (12) NOT NULL ,
  77.      CONSTRAINT User_PK PRIMARY KEY NONCLUSTERED (idUser)
  78.     )
  79. GO
  80.  
  81.  
  82. ALTER TABLE TrainCrew
  83.     ADD CONSTRAINT Relation_1 FOREIGN KEY
  84.     (
  85.      idStaff
  86.     )
  87.     REFERENCES Staff
  88.     (
  89.      idStaff
  90.     )
  91. GO
  92.  
  93. ALTER TABLE TrainCrew
  94.     ADD CONSTRAINT Relation_3 FOREIGN KEY
  95.     (
  96.      idTrainRide
  97.     )
  98.     REFERENCES TrainRide
  99.     (
  100.      idTrainRide
  101.     )
  102. GO
  103.  
  104. ALTER TABLE TrainRide
  105.     ADD CONSTRAINT Relation_4 FOREIGN KEY
  106.     (
  107.      idTrain
  108.     )
  109.     REFERENCES Train
  110.     (
  111.      idTrain
  112.     )
  113. GO
  114.  
  115. ALTER TABLE Reservation
  116.     ADD CONSTRAINT Relation_5 FOREIGN KEY
  117.     (
  118.      idTrainRide
  119.     )
  120.     REFERENCES TrainRide
  121.     (
  122.      idTrainRide
  123.     )
  124. GO
  125.  
  126. ALTER TABLE Reservation
  127.     ADD CONSTRAINT Relation_6 FOREIGN KEY
  128.     (
  129.      idUser
  130.     )
  131.     REFERENCES [User]
  132.     (
  133.      idUser
  134.     )
  135. GO
  136.  
  137. ALTER TABLE Train
  138.     ADD CONSTRAINT Relation_7 FOREIGN KEY
  139.     (
  140.      idStation
  141.     )
  142.     REFERENCES Station
  143.     (
  144.      idStation
  145.     )
  146. GO
  147.  
  148. ALTER TABLE Train
  149.     ADD CONSTRAINT Relation_8 FOREIGN KEY
  150.     (
  151.      idStation1
  152.     )
  153.     REFERENCES Station
  154.     (
  155.      idStation
  156.     )
  157. GO
Advertisement
Add Comment
Please, Sign In to add comment