The document creates a SALES database and defines tables for customers, salespeople, and orders. It inserts sample data and performs queries on the tables.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
29 views1 page
Create Database Sales
The document creates a SALES database and defines tables for customers, salespeople, and orders. It inserts sample data and performs queries on the tables.
( Number VARCHAR(10) PRIMARY KEY, Order_Date Datetime, SP_ID VARCHAR(10) FOREIGN KEY REFERENCES SALESPERSON, Cust_ID VARCHAR(12) FOREIGN KEY REFERENCES CUSTOMER, Amount MONEY ) ALTER TABLE SALESPERSON ADD Age1 INT CHECK(Age1 BETWEEN 18 AND 65); SELECT*FROM CUSTOMER; SELECT*FROM SALESPERSON ; SELECT*FROM ORDERS ; INSERT INTO SALESPERSON VALUES('101','Hailu','Male','1400',53); INSERT INTO SALESPERSON VALUES('102','Aster','Female','2400',47); INSERT INTO SALESPERSON VALUES('103','Azeb','Female','2000',38); INSERT INTO SALESPERSON VALUES('104','Muluken','Male','2500',31); INSERT INTO SALESPERSON VALUES('105','Tigist','Female','1500',59); INSERT INTO SALESPERSON VALUES('106','Meseret','Female','2800',26); INSERT INTO CUSTOMER VALUES('201','Hailu','Teshome','Bahir Dar','P'); INSERT INTO CUSTOMER VALUES('202','Aster','Abebe','Gondar','P'); INSERT INTO CUSTOMER VALUES('203','Azeb','Belete','Markos','H'); INSERT INTO CUSTOMER VALUES('204','Richard','Bale','Dessie','H'); INSERT INTO ORDERS VALUES('1','05/2/2000','102','201',640); INSERT INTO ORDERS VALUES('2','01/30/2000','105','204',1200); INSERT INTO ORDERS VALUES('3','07/14/2001','101','204',560); INSERT INTO ORDERS VALUES('4','01/29/2003','102','203',2500); INSERT INTO ORDERS VALUES('5','02/03/2003','104','202',800); INSERT INTO ORDERS VALUES('6','03/2/2003','104','202',920); INSERT INTO ORDERS VALUES('7','05/2/2003','104','204',350); SELECT Name, Salary FROM SALESPERSON WHERE Gender ='Female' AND Salary>=2400; SELECT SALESPERSON.Name FROM SALESPERSON WHERE NOT EXISTS (SELECT * FROM ORDERS WHERE SALESPERSON.SP_ID=ORDERS.SP_ID) SELECT Name,SALESPERSON .SP_ID ,Gender ,Salary FROM SALESPERSON JOIN ORDERS ON SALESPERSON .SP_ID =ORDERS .SP_ID GROUP BY Name,SALESPERSON .SP_ID ,Gender ,Salary HAVING COUNT (ORDERS.SP_ID )>=2
ALTER TABLE ORDERS NOCHECK CONSTRAINT ALL
DELETE FROM CUSTOMER WHERE Cust_id ='204';
USE master BACKUP DATABASE SALES TO DISK='D:\SALES1.BAK'; USE master DROP DATABASE SALES
USE master RESTORE DATABASE SALES FROM DISK='D:\SALES1.BAK';