Presentation is loading. Please wait.

Presentation is loading. Please wait.

ITEC 3220M Using and Designing Database Systems

Similar presentations


Presentation on theme: "ITEC 3220M Using and Designing Database Systems"— Presentation transcript:

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

2 SQL*Loader

3 SQL*Loader 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 Loader Files SQL*Loader takes either: or
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 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 The SQL*Loader Environment

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 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 The Control File (ship.ctl) - example
INFILE ‘ship.csv’ REPLACE INTO TABLE Ship FIELDS TERMINATED By ‘,’ OPTIONALLY ENCLOSED BY ‘”’ (shipNum, shipName, yearBuilt, capacity)

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 Execution of SQL*Loader
sqlldr control=ship.ctl

12 SQL Queries

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

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 Examples SELECT Order_Num FROM ORDERS WHERE Order_Num IN
FROM ORDER_LINE WHERE Part_Num =1234;

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 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 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 SQL Exercise (Cont’d) STUDENT (Primary key: Student_ID)
IS_QUALIFIED (Primary key: Faculty_ID, Course_ID) Faculty_ ID Course_ID Date_ Qualified 2143 ISM3112 9/1988 3467 ISM4212 9/1995 ISM4930 9/1996 4756 ISM3113 9/1991 Student_ ID Name 38214 Letersky 54907 Altvater 66324 Aiken 70542 Marra

20 SQL Exercise (Cont’d) FACULTY (Primary key: Faculty_ID)
SECTION (Primary key: Section_ID) Section_ID Course_ID 2712 ISM3113 2713 2714 ISM4212 2715 ISM4930 Faculty_ID Faculty_Name 2143 Birkin 3467 Berndt 4756 Collins

21 SQL Exercise (Cont’d) COURSE ((Primary key: Course_ID)
IS_REGISTERED (Primary key: Student_ID, Section_ID) Course_ID Course_ Name ISM3113 Syst Analysis ISM3112 Syst Design ISM4212 Database ISM4930 Networking Student_ID Section_ID Semester 38214 2714 I 54907 2715 66324 2713

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 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 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 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"

Similar presentations


Ads by Google