Professional Documents
Culture Documents
Database Management System 1: Data Definition Language
Database Management System 1: Data Definition Language
Database Management System 1: Data Definition Language
Where:
o Tbl_name - is the name of the table
o Column_lists – the lists of columns
o Expression – constraint added on each column (if any).
CREATE TABLE statement cont.
• Example:
CREATE TABLE STUDENTS
(USN_ID NUMBER (6) PRIMARY KEY,
LASTNAME VARCHAR (15) NOT NULL,
FIRSTNAME VARCHAR (15),
COURSE CHAR (4),
YR_LVL CHAR (5));
Data type
1. VARCHAR- Variable-length character data
2. CHAR - Fixed-length character data
3. NUMBER - Variable-length numeric data
4. DATE - Date and time values
5. LONG - Variable-length character data (up to 2 GB
6. CLOB - Character data (up to 4 GB)
7. RAW and LONG RAW - Raw binary data
8. BLOB - Binary data (up to 4 GB)
9. BFILE - Binary data stored in an external file (up to 4 GB)
10. ROWID - A base-64 number system representing the unique address of a row in its
table
Use the ALTER TABLE statement to:
• Add a new column after the table has been
created
• Modify an existing column definition
• Define a default value for the new column
• Drop existing column
• Rename a column
• Change table to a read-only status
Three (3) types of ALTER statement
• Example:
ALTER TABLE STUDENTS
ADD ADDRESS VARCHAR(15);
ALTER to MODIFY
Syntax:
ALTER TABLE tbl_name
MODIFY column_name [new]datatype[new](size);
Example:
ALTER TABLE STUDENTS
Example:
ALTER TABLE STUDENTS
DROP COLUMN ADDRESS;
Rename the table
To rename the table or change the existing
name of the table use the RENAME statement;
Syntax:
RENAME old_tbl_name TO new_tbl_name;
Example:
RENAME STUDENTS TO STUDYANTE;
Truncate Statement
To delete the values in the STUDENTS but leaving
it structure you may use the TRUNCATE
statement.
Syntax:
TRUNCATE TABLE tbl_name;
Example:
TRUNCATE TABLE STUDYANTE;
Dropping a table
Using DROP table statement will lose all the data in the
table and all the indexes associated in it.
Even if a rollback statement is issued the record in the
table will not be restored.
Syntax
DROP TABLE table ;
• Example:
DROP TABLE STUDYANTE;
Lesson Summary: