Advertisement
ProgNeo

Untitled

Oct 7th, 2022 (edited)
2,475
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 2.17 KB | None | 0 0
  1. CREATE TABLE [Pizza] (
  2.     P_ID INTEGER(4) NOT NULL,
  3.     P_NAME VARCHAR(15) NOT NULL,
  4.     P_COMPOS VARCHAR(50) NOT NULL,
  5.     P_COST INTEGER(3) NOT NULL,
  6.   CONSTRAINT [PK_PIZZA] PRIMARY KEY CLUSTERED
  7.   (
  8.   [P_ID] ASC
  9.   ) WITH (IGNORE_DUP_KEY = OFF)
  10.  
  11. )
  12. GO
  13. CREATE TABLE [Employees] (
  14.     E_ID INTEGER(4) NOT NULL,
  15.     E_NAME VARCHAR(50) NOT NULL,
  16.     E_BORN datetime NOT NULL,
  17.     E_SEX VARCHAR(1) NOT NULL,
  18.     E_ADDR VARCHAR(50) NOT NULL,
  19.     E_TEL VARCHAR(11) NOT NULL,
  20.     E_POST VARCHAR(30) NOT NULL,
  21.     E_SALARY INTEGER(8) NOT NULL,
  22.   CONSTRAINT [PK_EMPLOYEES] PRIMARY KEY CLUSTERED
  23.   (
  24.   [E_ID] ASC
  25.   ) WITH (IGNORE_DUP_KEY = OFF)
  26.  
  27. )
  28. GO
  29. CREATE TABLE [Clients] (
  30.     C_ID INTEGER(5) NOT NULL,
  31.     C_NAME VARCHAR(50) NOT NULL,
  32.     C_ADDR VARCHAR(50) NOT NULL,
  33.     C_TEL VARCHAR(11) NOT NULL,
  34.   CONSTRAINT [PK_CLIENTS] PRIMARY KEY CLUSTERED
  35.   (
  36.   [C_ID] ASC
  37.   ) WITH (IGNORE_DUP_KEY = OFF)
  38.  
  39. )
  40. GO
  41. CREATE TABLE [Orders] (
  42.     O_ID INTEGER(4) NOT NULL,
  43.     O_COMPOS INTEGER(4) NOT NULL,
  44.     O_CLIENT INTEGER(5) NOT NULL,
  45.     O_DATE datetime NOT NULL,
  46.     O_CASHIER INTEGER(4) NOT NULL,
  47.     O_COOK INTEGER(4) NOT NULL,
  48.     O_COURIER INTEGER(4) NOT NULL,
  49.   CONSTRAINT [PK_ORDERS] PRIMARY KEY CLUSTERED
  50.   (
  51.   [O_ID] ASC
  52.   ) WITH (IGNORE_DUP_KEY = OFF)
  53.  
  54. )
  55. GO
  56.  
  57.  
  58.  
  59. ALTER TABLE [Orders] WITH CHECK ADD CONSTRAINT [Orders_fk0] FOREIGN KEY ([O_COMPOS]) REFERENCES [Pizza]([P_ID])
  60. ON UPDATE CASCADE
  61. GO
  62. ALTER TABLE [Orders] CHECK CONSTRAINT [Orders_fk0]
  63. GO
  64. ALTER TABLE [Orders] WITH CHECK ADD CONSTRAINT [Orders_fk1] FOREIGN KEY ([O_CLIENT]) REFERENCES [Clients]([C_ID])
  65. ON UPDATE CASCADE
  66. GO
  67. ALTER TABLE [Orders] CHECK CONSTRAINT [Orders_fk1]
  68. GO
  69. ALTER TABLE [Orders] WITH CHECK ADD CONSTRAINT [Orders_fk2] FOREIGN KEY ([O_CASHIER]) REFERENCES [Employees]([E_ID])
  70. ON UPDATE CASCADE
  71. GO
  72. ALTER TABLE [Orders] CHECK CONSTRAINT [Orders_fk2]
  73. GO
  74. ALTER TABLE [Orders] WITH CHECK ADD CONSTRAINT [Orders_fk3] FOREIGN KEY ([O_COOK]) REFERENCES [Employees]([E_ID])
  75. ON UPDATE CASCADE
  76. GO
  77. ALTER TABLE [Orders] CHECK CONSTRAINT [Orders_fk3]
  78. GO
  79. ALTER TABLE [Orders] WITH CHECK ADD CONSTRAINT [Orders_fk4] FOREIGN KEY ([O_COURIER]) REFERENCES [Employees]([E_ID])
  80. ON UPDATE CASCADE
  81. GO
  82. ALTER TABLE [Orders] CHECK CONSTRAINT [Orders_fk4]
  83. GO
  84.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement