Presentation is loading. Please wait.

Presentation is loading. Please wait.

ITEC 3220M Using and Designing Database Systems Instructor: Prof. Z. Yang Course Website: ec3220m.htm Office: Tel.

Similar presentations


Presentation on theme: "ITEC 3220M Using and Designing Database Systems Instructor: Prof. Z. Yang Course Website: ec3220m.htm Office: Tel."— Presentation transcript:

1 ITEC 3220M Using and Designing Database Systems Instructor: Prof. Z. Yang Course Website: ec3220m.htm Office: Tel 3049

2 SQL*Loader

3 3 SQL*Loader is a bulk loader utility used for moving data from external files into an Oracle table. Tables must exist Loader works with the control file (file.ctl)

4 4 Loader Files SQL*Loader takes either: –two input files – a control file and a data file or –a single input file – a control file that contains a set of data and loads the data into a single Oracle table

5 5 Loader Files The data file contains data –each record is placed in one row, –fields can be delimited by ‘,’ or ‘|’ – can have extensions.csv or.dat The control file contains information about the data –specifies action: insert, replace, append –describes the data, indicates which tables and columns the data is to be loaded –has extension.ctl

6 6 The SQL*Loader Environment

7 7 The Log, Bad and Discard Files The log file (.log) – records SQL*Loader's activities during a load session and contains statistics on the load, error messages for records that cause errors It is important to review the log file after a load to make sure that no errors occurred! The bad file (.bad) – shows database errors, e.g. insert failure due to integrity constraint violation The discard file (.dis) –holds records that do not meet selection criteria specified in the SQL*Loader control file

8 8 The Data File (ship.csv) - example “001”,”Century”,”1986”,”2000” “002”,”Galaxy”,”1989”,”1500” “003”,”Horizon”,”1992”,”1600” “004”,”Infinity”,”1995”,”2500” “005”,”Journey”,”1998”,”2500” “006”, “Mercury”,”2001”,”3000”

9 9 The Control File (ship.ctl) - example INFILE ‘ship.csv’ REPLACE INTO TABLE Ship FIELDS TERMINATED By ‘,’ OPTIONALLY ENCLOSED BY ‘”’ (shipNum, shipName, yearBuilt, capacity)

10 10 Data in the Control File - example LOAD DATA INFILE * REPLACE INTO TABLE Ship FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' (shipNum, shipName, yearBuilt, capacity) BEGINDATA "001","Century","1986","2000" "002","Galaxy","1989","1500" "003","Horizon","1992","1600" "004","Infinity","1995","2500" "005","Journey","1998","2500" "006","Mercury","2001","3000"

11 11 Execution of SQL*Loader sqlldr control=ship.ctl

12 SQL Queries

13 13 SQL Queries Single table query Multiple table query –Nesting query Using IN Using EXISTS –Join Table

14 14 Joining Database Tables Ability to combine (join) tables on common attributes is most important distinction between a relational database and other databases Join is performed when data are retrieved from more than one table at a time Join is generally composed of an equality comparison between the foreign key and the primary key of related tables

15 15 Examples SELECT Order_Num FROM ORDERS WHERE Order_Num IN (SELECT Order_Num FROM ORDER_LINE WHERE Part_Num =1234;

16 16 Examples (Cont’d) SELECT Order_Num FROM ORDERS WHERE EXISTS (SELECT * FROM ORDER_LINE WHERE ORDERS.Order_Num = ORDERLINE.Order_Num AND Part_Num =1234;

17 17 Examples (Cont’d) SELECT S.Last, S.First, C.Last, C.First FROM SALES_REP S, CUSTOMER C WHERE S.Srep_Num = C. Srep_Num

18 18 SQL Exercise Write SQL code that will create the relations shown. Assume the following attribute data types: –Student_ID: integer –Student_Name: 25 characters –Faculty_ID: integer –Faculty_Name: 25 characters –Course_ID: 25 characters –Course_Name: 15 characters –Date_Qualified: date –Section_ID: integer –Semester: 7 characters

19 19 SQL Exercise (Cont’d) STUDENT (Primary key: Student_ID) Student_ ID Student_ Name 38214Letersky 54907Altvater 66324Aiken 70542Marra IS_QUALIFIED (Primary key: Faculty_ID, Course_ID) Faculty_ ID Course_I D Date_ Qualified 2143ISM31129/ ISM42129/ ISM49309/ ISM31139/ ISM31129/1991

20 20 SQL Exercise (Cont’d) FACULTY (Primary key: Faculty_ID) Faculty_I D Faculty_Name 2143Birkin 3467Berndt 4756Collins SECTION (Primary key: Section_ID) Section_IDCourse_ID 2712ISM ISM ISM ISM4930

21 21 SQL Exercise (Cont’d) COURSE ((Primary key: Course_ID) Course_IDCourse_ Name ISM3113Syst Analysis ISM3112Syst Design ISM4212Database ISM4930Networking IS_REGISTERED (Primary key: Student_ID, Section_ID) Student_I D Section_I D Semester I I I I

22 22 SQL Exercise (Cont’d) Write SQL queries to answer the following questions: –Display the course ID and course name for all courses with an ISM prefix. –Display all the courses (Course_Name) for which Professor Berndt has been qualified. –Is any instructor qualified to teach ISM 3113 and not qualified to teach ISM 4930? –How many students are enrolled in section 2714 during semester I – 2001? –Which students were not enrolled in any courses during semester I – 2001?

23 23 Lab Instruction Login to sit.yorku.ca Start Oracle SQL*PLUS environment by typing the following command: sqlplus When prompted for the username/password enter (where your_username is your AML username) at the username prompt and your AML password at the password prompt.

24 24 Lab Tips To list all tables you have in your Oracle account use the following SQL command: select table_name from user_tables; To describe a given Oracle table use the following Oracle environment command (note that this is not an SQL command): desc tablename (where tablename is the name of the table that you have in your account)

25 25 SQL Plus Editing Commands Add text at end of current line: A text Change current line: type the line number Change text in current line: C/old/new Insert a line following current line: I


Download ppt "ITEC 3220M Using and Designing Database Systems Instructor: Prof. Z. Yang Course Website: ec3220m.htm Office: Tel."

Similar presentations


Ads by Google