SQL Statements Used in the Course
Data manipulation language (DML) Data definition language (DDL)
SELECT
UPDATE
MERGE
INSERT
DELETE
CREATE ALTER
DROP RENAME
COMMENT
TRUNCATE
Transaction control
COMMIT
SAVEPOINT
Data control language (DCL
GRANT
REVOKE
ACTIVITY (1/2 crosswise)
-Research the definition and syntax of the
following:
SELECT -> select * from tablename;
UPDATE
MERGE
INSERT
DELETE
Database Management System 1
Data Definition Language
Lesson Objective
After completing this lesson, the student should be able
to:
• Categorize differences between database objects.
• Review and analyze the structure of the table.
• Lists and identify the usage of different data types.
• Create a simple table.
• Modify, drop or delete a column after the table is created.
Data
Definition
Language
(DDL)
is a subset of SQL.
It is a language for describing data and
its relationships in a database.
Database Objects
A database objects is composed of the following:
1. Synonym – Gives alternative name to an object.
2. Index – improves the performance of some queries.
3. Sequence – generate numeric values.
4. View – logically represents subsets of data from one or
more table.
5. Table –is also known as basic storage composed of rows
and columns.
Synonym
Table Naming Rule
Table names and column names must:
• Begin with a letter uppercase, lowercase or a
combination will do.
• At least 30 characters long.
• Must only have a letter from A–Z, or a–z, 0–9, and
special character _(underscore), $ (dollar sign),
and # (sharp symbol)
• Must not duplicate or use the name of another
object owned by the same user
• Not be an Oracle server–reserved word
CREATE TABLE statement
To create a table a user must have
• The CREATE TABLE privilege
• A storage area
• Syntax:
CREATE TABLE tbl_name
(Column_lists datatype (size) [default expression] ;
• 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
1. Alter to ADD – add new column after the
table has been created
2. Alter to DROP – delete specific column
3. Alter to MODIFY – modify an existing column
either change the data type size and data
type.
ALTER to ADD
• Syntax:
ALTER TABLE tbl_name
ADD column_name datatype(size);
• 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
MODIFY LASTNAME VARCHAR(20);
ALTER to DROP
• Syntax:
ALTER TABLE tbl_name
DROP COLUMN column_name;
• 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 TABLE 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:
In this lesson, you should have learned the following.
• Create new table by using the CREATE table statement.
• Add, modify or drop exiting column using the ALTER statement.
• Change the name of the table using the RENAME statement.
• Delete the table using the DROP statement
• Remove all rows in the table using the TRUNCATE statement.

Lesson 3 DDL .ppt DDL for database management system

  • 1.
    SQL Statements Usedin the Course Data manipulation language (DML) Data definition language (DDL) SELECT UPDATE MERGE INSERT DELETE CREATE ALTER DROP RENAME COMMENT TRUNCATE Transaction control COMMIT SAVEPOINT Data control language (DCL GRANT REVOKE
  • 2.
    ACTIVITY (1/2 crosswise) -Researchthe definition and syntax of the following: SELECT -> select * from tablename; UPDATE MERGE INSERT DELETE
  • 3.
    Database Management System1 Data Definition Language
  • 4.
    Lesson Objective After completingthis lesson, the student should be able to: • Categorize differences between database objects. • Review and analyze the structure of the table. • Lists and identify the usage of different data types. • Create a simple table. • Modify, drop or delete a column after the table is created.
  • 5.
    Data Definition Language (DDL) is a subsetof SQL. It is a language for describing data and its relationships in a database.
  • 6.
    Database Objects A databaseobjects is composed of the following: 1. Synonym – Gives alternative name to an object. 2. Index – improves the performance of some queries. 3. Sequence – generate numeric values. 4. View – logically represents subsets of data from one or more table. 5. Table –is also known as basic storage composed of rows and columns.
  • 7.
  • 8.
    Table Naming Rule Tablenames and column names must: • Begin with a letter uppercase, lowercase or a combination will do. • At least 30 characters long. • Must only have a letter from A–Z, or a–z, 0–9, and special character _(underscore), $ (dollar sign), and # (sharp symbol) • Must not duplicate or use the name of another object owned by the same user • Not be an Oracle server–reserved word
  • 9.
    CREATE TABLE statement Tocreate a table a user must have • The CREATE TABLE privilege • A storage area • Syntax: CREATE TABLE tbl_name (Column_lists datatype (size) [default expression] ; • 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).
  • 10.
    CREATE TABLE statementcont. • 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));
  • 11.
    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
  • 12.
    Use the ALTERTABLE 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
  • 13.
    Three (3) typesof ALTER statement 1. Alter to ADD – add new column after the table has been created 2. Alter to DROP – delete specific column 3. Alter to MODIFY – modify an existing column either change the data type size and data type.
  • 14.
    ALTER to ADD •Syntax: ALTER TABLE tbl_name ADD column_name datatype(size); • Example: ALTER TABLE STUDENTS ADD ADDRESS VARCHAR(15);
  • 15.
    ALTER to MODIFY •Syntax: ALTER TABLE tbl_name MODIFY column_name [new]datatype[new](size); • Example: ALTER TABLE STUDENTS MODIFY LASTNAME VARCHAR(20);
  • 16.
    ALTER to DROP •Syntax: ALTER TABLE tbl_name DROP COLUMN column_name; • Example: ALTER TABLE STUDENTS DROP COLUMN ADDRESS;
  • 17.
    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 TABLE STUDENTS TO STUDYANTE;
  • 18.
    Truncate Statement • Todelete the values in the STUDENTS but leaving it structure you may use the TRUNCATE statement. • Syntax: TRUNCATE TABLE tbl_name; • Example: TRUNCATE TABLE STUDYANTE;
  • 19.
    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;
  • 20.
    Lesson Summary: In thislesson, you should have learned the following. • Create new table by using the CREATE table statement. • Add, modify or drop exiting column using the ALTER statement. • Change the name of the table using the RENAME statement. • Delete the table using the DROP statement • Remove all rows in the table using the TRUNCATE statement.