Advertisement
Guest User

Untitled

a guest
Nov 24th, 2016
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 1.94 KB | None | 0 0
  1. Create Table Customer(
  2.     cid INTEGER NOT NULL auto_increment,
  3.     cname char(80) NOT NULL,
  4.     email CHAR(40) NOT NULL,
  5.     UNIQUE (email),
  6.     address char(200),
  7.     password char(16) NOT NULL,
  8.     Primary Key(cid)
  9. );
  10.  
  11. Create Table City(
  12.     cityid integer NOT NULL auto_increment,
  13.     title CHAR(50) NOT NULL,
  14.     state char(2) NOT NULL,
  15.     Primary key(cityid))auto_increment = 0;
  16.  
  17. CREATE TABLE Flight(
  18.     fid INTEGER NOT null auto_increment,
  19.     fnumber integer,
  20.     fdate DATE NOT NULL,
  21.     ftime TIME NOT NULL,
  22.     price REAL NOT NULL,
  23.     class INTEGER NOT NULL,
  24.     capacity INTEGER NOT NULL,
  25.     available INTEGER NOT NULL,
  26.     orig INTEGER NOT NULL,
  27.     dest INTEGER NOT NULL,
  28.     PRIMARY KEY(fid),
  29.     Foreign KEY(orig) references City(cityid) ON DELETE cascade,
  30.     Foreign key(dest) references City(cityid) ON DELETE cascade) AUTO_INCREMENT = 0;
  31.  
  32. CREATE TABLE Reservation(
  33.     ordernum INTEGER NOT null auto_increment,
  34.     cid integer not null,
  35.     dfid integer not null,
  36.     rfid integer,
  37.     qty integer not null,
  38.     cardnum CHAR(16) not null,
  39.     cardmonth integer not null,
  40.     cardyear integer not null,
  41.     order_date DATE,
  42.     PRIMARY KEY(ordernum),
  43.     Foreign KEY(cid) references Customer(cid) ON DELETE cascade,
  44.     Foreign key(dfid) references Flight(fid) ON DELETE cascade,
  45.     Foreign key(rfid) references Flight(fid) ON DELETE cascade)
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52. DELIMITER $$   
  53. Create Trigger reservation_all
  54.     after insert on Reservation
  55.     for each row
  56.     begin
  57.         update Reservation
  58.         set order_date = Current_Date
  59.         where ordernum = New.ordernum;
  60.         update Flight X
  61.         set available = (Select available
  62.                          from Flight f
  63.                          where (f.fid = new.dfid)) - new.qty
  64.         where X.fid = new.dfid;
  65.         update Flight X1
  66.         set available = (Select available
  67.                          from Flight f
  68.                          where (f.fid = new.rfid)) - new.qty
  69.         where X1.fid = new.rfid;
  70.         end;
  71. $$
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement