- use customer_DB
- go;
- --create Customer table
- create table Customer
- (CUSTOMER_ID SMALLINT Primary key identity(1,1),
- FIRST_NAME varchar(20),LAST_NAME varchar(20),
- ADDRESS VARCHAR (45),CITY VARCHAR (10),
- STATE CHAR (2),
- ZIP SMALLINT,
- EMAIL VARCHAR(40)
- );
- --create Product table
- create table Product (PRODUCT_ID SMALLINT,PRODUCT_DESC varchar(15),PRODUCT_QTY SMALLINT,
- CONSTRAINT PK_Product_PRODUCT_ID PRIMARY KEY (PRODUCT_ID)
- );
- --create order_tbl table
- create table order_tbl(
- ORDER_ID INT Primary key identity(1,1),
- CUSTOMER_ID SMALLINT,
- PRODUCT_ID SMALLINT,
- CONSTRAINT FK_Order_CUSTOMER_ID FOREIGN KEY (CUSTOMER_ID) REFERENCES Customer (CUSTOMER_ID),
- CONSTRAINT FK_Order_PRODUCT_ID FOREIGN KEY (PRODUCT_ID) REFERENCES Product (PRODUCT_ID)
- );
- --create Order_Items table
- create table Order_Items (ORDER_ID INT,
- CUSTOMER_ID SMALLINT,
- PRODUCT_QTY SMALLINT,
- CONSTRAINT PK_Order_Items_ORDER_ID PRIMARY KEY (ORDER_ID),
- CONSTRAINT FK_Order_Items_ORDER_ID FOREIGN KEY (ORDER_ID) REFERENCES order_tbl(ORDER_ID),
- CONSTRAINT FK_Order_Items_CUSTOMER_ID FOREIGN KEY (CUSTOMER_ID) REFERENCES Customer (CUSTOMER_ID)
- );
- --create stock table
- create table stock(
- STOCK_ID SMALLINT Primary key identity(1,1),
- STOCK_DESC VARCHAR (15),
- STOCK_QTY SMALLINT
- );
[text] Jerrys Ranch
Viewer
Editor
You can edit this paste and save as new: