0% found this document useful (0 votes)
70 views17 pages

DR - Osama Lab 2 Creating and Deleting Tables

The document describes setting up an Oracle database lab. It includes instructions on downloading Oracle software, logging in, using SQL commands like CREATE TABLE to set up tables for a student registration database with tables for students, courses, prerequisites, departments, instructors, sections, and grade reports. It also covers using commands like DESC to view table descriptions and DROP TABLE to delete tables.

Uploaded by

DA NA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
70 views17 pages

DR - Osama Lab 2 Creating and Deleting Tables

The document describes setting up an Oracle database lab. It includes instructions on downloading Oracle software, logging in, using SQL commands like CREATE TABLE to set up tables for a student registration database with tables for students, courses, prerequisites, departments, instructors, sections, and grade reports. It also covers using commands like DESC to view table descriptions and DROP TABLE to delete tables.

Uploaded by

DA NA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

Lab 2

• Oracle Software
• User name and password
• Data Definition Language (DDL)
• Creating Tables
• Viewing description of a table
• Deleting Tables
• Exercise

Dr. Osama Al-Haj Hassan


1
Oracle Software
• During semester, we will use “Oracle 9i”.

• In “Oracle 9i”, we will only use “SQL Plus”.

• If “Oracle 9i” is installed on your windows system, you can run


SQL Plus as follows (Path might differ based on installation):
– Start Menu  All Programs  Oracle for Windows NT  SQL Plus 8.0

• SQL Plus is a command line window using which you can write
commands to build and manipulate databases.

2
User Name and Password
• When you run SQL Plus, you will be prompted for a user name
and a password, you can use one of the following:
– UserName: system Password: manager
– UserName: Scott Password: tiger

3
Setting Line Size
• Sometimes, the default line size is short.
– So, output would be broken to multiple lines.

• To increase line size, you use this command:


– set line $numOfChars;

• Example:
– set line 300;

4
Spool Command
• If you do some work on SQL Plus and close it, then anything
that appears on SQL Plus window will be lost.

• To save all what appears on SQL Plus window, you need to


spool it to an external file using the following command.

• Spool $FilePath;

• Example:
– Spool “c:/myfile.txt”;

• Now, everything that appears on SQL Plus window will be


5
saved in “c:/myfile.txt”.
Data Definition Language (DDL)
• Used to change the structure of the database.

• Part of DDL is:


– Creating tables.
– Deleting tables.
– Changing table definition.

6
Create Table
• Syntax:
– create table $table_name
(
$attribute_name1 $data_type,
$attribute_name2 $data_type
);

• You can have more attributes such that you provide a comma
after each attribute definition.

7
Examples
• create table t (
a number,
b varchar2(10)
);

t a b

8
Examples
• create table orders (
order_id number,
order_date date,
customer_id number,
customer_name varchar2(40)
);

orders order_id order_date customer_id customer_name

9
View description of a table
• The ‘desc’ command outputs the description of the table
which includes attribute names and their data types.

• Syntax:
– desc $table_name;

• Example:
– desc t;
– desc orders;

10
Deleting Tables
• ‘drop table’ command deletes a table.

• Syntax:
– drop table $table_name;

• Examples:
– drop table t;
– drop table orders;

11
Excersice

• Create the registration database illustrated in the following


slides.

• Data type is given below each attribute name.

12
The “ed” Command
• Unfortunately, SQL Plus is not an easy interface to work with.

• It is not possible to move cursor forward, backward, top, or


down. But, you can use backspace in one line.

• As a result, if you made a mistake while writing a command, it


is not easy to fix it.

• A way to go around this is using the “ed” command.

13
Using “ed” Command
• Write the following command which contains a mistake.
create tab
(

• You realized that you made a mistake “tab” instead of “table”.

• End your command with a semicolon “;”.

• Now write the “ed” command.


– ed;

14
Using “ed” Command
• Notepad window appears containing the command you wrote last.
• Also, there is a backslash “/” at the end of the command.
Create tab
(

/
• Correct your command and make sure to do the following:
– Do not write a “;” at the end of your command.
– Do not remove the backslash “/” character.

• Now close the Notepad window and click yes to save your changes.

• The corrected command will show up in the SQL Plus window.

• Now, write a semicolon “;” and hit enter to execute your command.
15
Registration Database

student std_id std_name class dep_id


number varchar2(30) number number

course crs_Id crs_name credit dep_id


number varchar2(30) number number

prerequisite crs_id prereq_id


number number

department dep_id dep_name


number varchar2(30)
16
Registration Database

instructor ins_id ins_name dep_id


number varchar2(30) number

section sec_id crs_id semester year ins_id


number number number number number

grade_report std_id sec_id crs_id semester year grade


number number number number number number

17

You might also like