Bài tập ôn tập cơ sở dữ liệu SQL

3 4.6K 37
Bài tập ôn tập cơ sở dữ liệu SQL

Đang tải... (xem toàn văn)

Thông tin tài liệu

Exercise 2 1. Create a new database called ‘Flight_Management’ 2. Use SQL Query Analyzer to work w

Exercise 2 1. Create a new database called ‘Flight_Management’ 2. Use SQL Query Analyzer to work with Flight_Management database and create a SQL script file follow those steps: 1. Create tables and insert data as follows: Flight Column Name Data Type Length Allow NullsAircraft_code char 5 Aircode char 2 Type varchar 10 Source varchar 15 Destination varchar 15 Category varchar 15 Dep_time varchar 15 x Journey_hrs int 4 x Flight_details Column Name Data Type Length Allow NullsAircraft_code char 5 Class_code char 2 Fare numeric 5 Seats numeric 5 Flight_days Column Name Data Type Length Allow NullsAircraft_code char 5 day_code int 4 insert the following data into tables Flight table Aircraft_code Aircode Type Source Destination Category Dep_time Journey_hrs9W01 9W Airbus Cal Che D 15.30 3 9W02 9W Airbus Mum Del D 9.30 2 9W03 9W Airbus Che Mum D 10.45 2 AI01 AI Boeing Cal NY I 2.20 18 AI02 AI Boeing Mum NY I 1.30 20 Flight_details 9W01 E 6100 300 9W01 Ex 6895 150 9W02 E 5900 300 9W02 Ex 6850 150 9W03 E 4175 300 9W03 Ex 5400 150 AI01 E 72215 350 AI01 Ex 77145 175 AI01 FC 81215 100 Flight_days table Aircraft_code day_code9W01 1 9W01 2 AI01 2 AI02 1 AI03 2 BA01 2 Constraints (Student must use ‘Alter Table’ statement to Apply them) 1. Apply the Default Constraint to the Type column of Flight table with value is Airbus. 2. Apply the Primary Key Constraint for Aircraft_code of Flight table, and the Composite Primary Key Constraint for the Aircraft_code and Class_code of the Flight_details table. 3. Create a References Constraint between Flight table and Flight_details table on Aircraft_code named ‘FK_Contr1’ 2. Display total number of domestic flight (Category=‘D’) 3. Display flight detail has fly at Monday (day_code =2) 4. Create a view named ‘Flight_List’ as following: (the list must sorted by Aircode, Type, ClassCode, Fare, Daycode) Aircode Type ClassCode Fare Daycode 9W Airbus Fx 5000 1 9W Airbus Fx 5000 2 9W Airbus Fx 5000 1 AI Boeing Ec 4500 2 AI Boeing Ec 4500 1 5. Modify the view named ‘Flight_List’ such that you can create an index on it. (Hint: Add ‘With SchemaBinding’ option) 6. Create an index named ‘indFlight_List’ on the (‘Aircode,’ ClassCode) column of the ‘Flight_List’ view. 7. Display flight details that has Fare = 5000 8. Drop References Constraint between Flight table and Flight_details 9. Create an Delete Trigger named ‘tgDeleteAll’ on the Flight table to prevent you from deleting a row has Aircarft_code =’9W01’ and display a notice ‘You can not delete’ 10. Create a stored procedure named ‘spDropFlight’ that accept an Aircode as parameter. The stored procedure will delete all Flight which has the Aircode like parameter Notes: You must ensure that this action will completely. . 2. Use SQL Query Analyzer to work with Flight_Management database and create a SQL script file follow those steps: 1.

Ngày đăng: 31/08/2012, 16:33

Từ khóa liên quan

Tài liệu cùng người dùng

Tài liệu liên quan