DR - Osama Lab 2 Creating and Deleting Tables
DR - Osama Lab 2 Creating and Deleting Tables
• Oracle Software
• User name and password
• Data Definition Language (DDL)
• Creating Tables
• Viewing description of a table
• Deleting Tables
• Exercise
• 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.
• 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.
• Spool $FilePath;
• Example:
– Spool “c:/myfile.txt”;
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)
);
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
12
The “ed” Command
• Unfortunately, SQL Plus is not an easy interface to work with.
13
Using “ed” Command
• Write the following command which contains a mistake.
create tab
(
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.
• Now, write a semicolon “;” and hit enter to execute your command.
15
Registration Database
17