SQL script to create an Inventory Database with tables for Suppliers, Products, Customers, Orders, and Stock. Includes data insertion and table deletion.
Tables:
-
SUPPLIER: Stores information about suppliers.
- Columns:
SID,SNAME,SADD,SCITY,SPHONE,EMAIL - Primary Key:
SID - Unique Constraint:
SPHONE - Default Value:
SCITYdefaults to 'DELHI'
- Columns:
-
PRODUCT: Stores information about products.
- Columns:
PID,PDESC,PRICE,CATEGORY,SID - Primary Key:
PID - Foreign Key:
SID(referencesSUPPLIER.SID) - Check Constraints:
PRICEmust be greater than 0.CATEGORYmust be one of 'IT', 'HA', or 'HC'.
- Columns:
-
STOCK: Stores stock levels for products.
- Columns:
PID,SQTY,ROL,MOQ - Primary Key:
PID(also a foreign key) - Foreign Key:
PID(referencesPRODUCT.PID) - Check Constraints:
SQTYmust be greater than or equal to 0.ROLmust be greater than 0.MOQmust be greater than or equal to 5.
- Columns:
-
CUST (Customer): Stores customer information.
- Columns:
CID,CNAME,ADDRESS,CITY,PHONE,EMAIL,DOB - Primary Key:
CID - Check Constraint:
DOBmust be before '01-JAN-2000'.
- Columns:
-
ORDERS: Stores order information.
- Columns:
OID,ODATE,PID,CID,OQTY - Primary Key:
OID - Foreign Keys:
PID(referencesPRODUCT.PID)CID(referencesCUST.CID)
- Check Constraint:
OQTYmust be greater than or equal to 1.
- Columns:
- The script also includes
INSERTstatements to populate the tables with sample data andDROP TABLEstatements at the end to remove the tables.