Advertisement
Dinmrmr

Untitled

Dec 26th, 2016
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 1.91 KB | None | 0 0
  1. --создание таблиц
  2. create table city (
  3.     id int primary key,
  4.     name nvarchar(30) not null
  5. )
  6. commit;
  7.  
  8. create table t_office (
  9.     id int primary key,
  10.     name nvarchar(30) not null,
  11.     id_city int not null
  12. )
  13. commit;
  14.  
  15. alter table t_office add constraint fk_t_office_city
  16. foreign key(id_city) references city(id);
  17. commit;
  18.  
  19. create table bus (
  20.     id int primary key,
  21.     auto_mark nvarchar(30) not null,
  22.     place_count int not null
  23. )
  24. commit;
  25.  
  26. create table driver (
  27.     id int primary key,
  28.     name nvarchar(30) not null,
  29.     id_city int not null
  30. )
  31. commit;
  32.  
  33. alter table driver add constraint fk_driver_city
  34. foreign key(id_city) references city(id);
  35. commit;
  36.  
  37. create table time_table (
  38.     id int primary key,
  39.     city_from int not null,
  40.     city_where int not null,
  41.     start_time time not null,
  42.     go_time time not null,
  43.     cost int not null
  44. )
  45. commit;
  46. alter table time_table add constraint fk_time_table_city
  47. foreign key(city_from) references city(id);
  48.  
  49. alter table time_table add constraint fk2_time_table_city
  50. foreign key(city_where) references city(id);
  51. commit;
  52.  
  53.  
  54. create table voyage (
  55.     id int primary key,
  56.     id_time_table int not null,
  57.     id_bus int not null,
  58.     dr_date date not null,
  59.     id_driver int not null
  60. )
  61. commit;
  62.  
  63. alter table voyage add constraint fk_voyage_time_table
  64. foreign key(id_time_table) references time_table(id);
  65.  
  66. alter table voyage add constraint fk_voyage_bus
  67. foreign key(id_bus) references bus(id);
  68.  
  69. alter table voyage add constraint fk_voyage_driver
  70. foreign key(id_driver) references driver(id);
  71. commit;
  72.  
  73. create table ticket (
  74.     id int primary key,
  75.     sell_time datetime not null,
  76.     id_t_office int not null,
  77.     id_voyage int not null,
  78.     passanger_name nvarchar(50) not null
  79. )
  80. commit;
  81. alter table ticket add constraint fk_ticket_t_office
  82. foreign key(id_t_office) references t_office(id);
  83.  
  84. alter table ticket add constraint fk_ticket_voyage
  85. foreign key(id_voyage) references voyage(id);
  86. commit;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement