Professional Documents
Culture Documents
Handout 1
Handout 1
Handout 1
The objective of this handout is to enable you to create a relational database schema in
Oracle.
To start open Oracle Database 10g Express Edition Go to Database Home Page
Username: System
Password: mcalab1234
Opens a new page that has the options of administration, Object Browser, SQL and Utilities.
Click on SQL.
Opens a page with the options of SQL commands, SQL scripts and Query Builder. Select SQL
Commands.
The following commands will help you create, alter and insert data into the schema.
Data Types supported by Oracle.
Data Type Description
String Data Types
CHAR(size) A FIXED length string (can contain letters, numbers, and special
characters). The size parameter specifies the column length in
characters - can be from 0 to 255. Default is 1
VARCHAR(size) A VARIABLE length string (can contain letters, numbers, and special
characters). The size parameter specifies the maximum column length
in characters - can be from 0 to 65535
BINARY(size) Equal to CHAR (), but stores binary byte strings. The size parameter
specifies the column length in bytes. Default is 1
MCA 23: Database Management System
Integer Data Types
BOOL Zero is considered as false, nonzero values are considered as true.
INT(size) A medium integer. Signed range is from -2147483648 to 2147483647.
Unsigned range is from 0 to 4294967295. The size parameter specifies
the maximum display width (which is 255)
FLOAT(size, d) A floating point number. The total number of digits is specified in size.
The number of digits after the decimal point is specified in the d
parameter.
Date Data Types
DATE A date. Format: YYYY-MM-DD. The supported range is from '1000-
01-01' to '9999-12-31'
TIMESTAMP(fsp) A timestamp. TIMESTAMP values are stored as the number of
seconds since the Unix epoch ('1970-01-01 00:00:00' UTC). Format:
YYYY-MM-DD hh:mm:ss.
Create Command: -
The CREATE TABLE statement is used to create a new table in a database. The example has
the mechanism of giving a primary key in the create table command itself.
General Syntax Example
CREATE TABLE table_name ( CREATE TABLE Persons (
column1 datatype, ID int NOT NULL,
column2 datatype, LastName varchar(255) NOT NULL,
column3 datatype, FirstName varchar(255),
.... Age int,
); PRIMARY KEY (ID)
);
Creating table with a primary key and a foreign key
Orders table has a foreign key on persons CREATE TABLE Orders (
table created above OrderID int NOT NULL,
OrderNumber int NOT NULL,
PersonID int,
PRIMARY KEY (OrderID),
FOREIGN KEY (PersonID)
REFERENCES Persons(ID)
);
To create a FOREIGN KEY constraint on the CREATE TABLE Orders (
"Person(ID)" column when the "Orders" OrderID int NOT NULL,
table is already created using the alter table OrderNumber int NOT NULL,
command. PersonID int,
PRIMARY KEY (OrderID)
);
Using the above commands, the student is expected to complete the following assignment
MCA 23: Database Management System
Assignment
Please create the following database schema with the data in each of the tables.
The arrows depict the foreign key references and the underlined column denotes the primary
key of that table.
Create the above tables and insert the following data into the created tables.
MCA 23: Database Management System