[text] Jerrys Ranch

Viewer

copydownloadembedprintName: Jerrys Ranch
  1. use customer_DB
  2. go;
  3.  
  4. --create Customer table
  5. create table Customer 
  6.         (CUSTOMER_ID SMALLINT Primary key identity(1,1), 
  7.                 FIRST_NAME varchar(20),LAST_NAME varchar(20),
  8.                 ADDRESS VARCHAR (45),CITY VARCHAR (10),
  9.                 STATE CHAR (2),
  10.                 ZIP SMALLINT,
  11.                 EMAIL VARCHAR(40)
  12.                 );
  13. --create Product table
  14. create table Product  (PRODUCT_ID   SMALLINT,PRODUCT_DESC varchar(15),PRODUCT_QTY SMALLINT,
  15.                        CONSTRAINT PK_Product_PRODUCT_ID PRIMARY KEY (PRODUCT_ID)
  16.                         );
  17.  
  18. --create order_tbl table
  19. create table order_tbl(
  20.         ORDER_ID INT Primary key identity(1,1),
  21.                 CUSTOMER_ID SMALLINT, 
  22.                 PRODUCT_ID SMALLINT,
  23.                 CONSTRAINT FK_Order_CUSTOMER_ID  FOREIGN KEY (CUSTOMER_ID)  REFERENCES Customer (CUSTOMER_ID),
  24.                 CONSTRAINT FK_Order_PRODUCT_ID  FOREIGN KEY (PRODUCT_ID)  REFERENCES Product (PRODUCT_ID)
  25.                 );
  26.  
  27. --create Order_Items table
  28. create table Order_Items (ORDER_ID INT,
  29.                            CUSTOMER_ID SMALLINT,
  30.                                                    PRODUCT_QTY SMALLINT,
  31.                                                    CONSTRAINT PK_Order_Items_ORDER_ID PRIMARY KEY (ORDER_ID),
  32.                            CONSTRAINT FK_Order_Items_ORDER_ID  FOREIGN KEY (ORDER_ID)  REFERENCES order_tbl(ORDER_ID), 
  33.                                                    CONSTRAINT FK_Order_Items_CUSTOMER_ID  FOREIGN KEY (CUSTOMER_ID)  REFERENCES Customer (CUSTOMER_ID)
  34.                    );
  35.  
  36.  
  37. --create stock table
  38. create table stock(
  39.                    STOCK_ID SMALLINT Primary key identity(1,1),
  40.                                    STOCK_DESC  VARCHAR (15),
  41.                                    STOCK_QTY SMALLINT
  42.                     );

Editor

You can edit this paste and save as new:


File Description
  • Jerrys Ranch
  • Paste Code
  • 29 Nov-2022
  • 1.5 Kb
You can Share it: