Professional Documents
Culture Documents
Database Objects:
A database objects is composed of the following:
Table Structure:
Tables can be created at any time, even if the users are
using the database at the same time while creating a new
table.
There is no need to specify the size of a table. The size is
ultimately defined by the amount of space allocated to
the database as a whole. As a database administrator, it is
important to estimate and know how much space a table
will use over time. Sometimes it depends on the data type
size and the amount of data stored in the table.
_____________________________________________________________________________________
2
MODULE OF INSTRUCTION
owned by the same Oracle server user. Meaning using
oracle reserved word like for example, table, view
database is not allowed, as well table name that has been
created by the other users.
Names must not be an Oracle server–reserved word.
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
_____________________________________________________________________________________
4
MODULE OF INSTRUCTION
After the table has been created, by any chance that a user
might need to change the table structure for any of the
following reasons:
• You omitted a column.
• Your column definition or its name needs to be
changed.
• You need to remove columns.
• You want to put the table into the read-only mode
ALTER to ADD
Syntax:
ALTER TABLE tbl_name
ADD column_name datatype(size);
Example:
ALTER TABLE STUDENTS
ADD ADDRESS VARCHAR(15);
Use again DESC command to confirm that the
ADDRESS column is added in the column. From 5
columns it is now compose of 6 columns because of
the ALTER statement. Note the since the table is alter
form 5 to 6 column this only means that when a user
will insert or add a new values to this table, user must
provide now a data for the column ADDRESS.
Example of Insert:
_____________________________________________________________________________________
6
MODULE OF INSTRUCTION
INSERT INTO STUDENTS VALUES
(400,'ALMAZAN','MARY','BSIM','2','PASIG'
)
Text in underline is the values for the column
ADDRESS.
Notice that when a user try to view the whole
values of STUDENTS table the address of the
students who are insert before the user altered the
table are set to NULL.
ALTER to MODIFY
Syntax:
ALTER TABLE tbl_name
MODIFY column_name [new]datatype[new](size);
Supposed that a user wanted to add additional value for
the STUDENTS table but it so happen that the values
trying to insert in column lastname is too large. See
figure below:
Example:
ALTER TABLE STUDENTS
MODIFY LASTNAME VARCHAR(20);
_____________________________________________________________________________________
8
MODULE OF INSTRUCTION
ALTER to DROP
Syntax:
ALTER TABLE tbl_name
DROP COLUMN column_name;
Supposed that the column address is no longer used and
to save space you may use the ALTER to DROP
statement.
Example:
ALTER TABLE STUDENTS
DROP COLUMN ADDRESS;
To view and confirm that the column ADDRESS has
been deleted you may use the DESC command.
table:
Example:
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;
_____________________________________________________________________________________
10
MODULE OF INSTRUCTION
table is still intact.
Dropping a Table
All records in the table will be deleted as well as
it structure when you drop table has been issued,
A rollback statement will also help retrieve the
record after the DROP statement is issued if
PURGE statement has been applied.
Syntax
DROP TABLE table
In the syntax, table is the name of the table.
Guidelines
• All the data is deleted from the table.
• Any views and synonyms remain, but are invalid.
• Any pending transactions are committed.
• Only the creator of the table or a user with the DROP
ANY TABLE privilege can remove a table.
• Example:
DROP TABLE STUDENTS;
Using this will delete permanently the
STUDYANTE table as shown below.
Lesson Summary:
In this lesson you should have learned how to:
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.
Terms to Remember!
BFILE - Binary data stored in an external file (up to 4 GB)
BLOB - Binary data (up to 4 GB)
CHAR - Fixed-length character data
CLOB - Character data (up to 4 GB)
DATE - Date and time values
DROP TABLE - it is a statement that moves a table to the
recycle bin
Index – improves the performance of some queries.
LONG - Variable-length character data (up to 2 GB
NUMBER - Variable-length numeric data
RAW and LONG RAW - Raw binary data
ROWID - A base-64 number system representing the unique
address of a row in its table
Sequence – generate numeric values.
Synonym – Gives alternative name to an object.
Table – basic unit of storage composed of rows and columns
VARCHAR- Variable-length character data
View – logically represents subsets of data from one or more
_____________________________________________________________________________________
12
MODULE OF INSTRUCTION
table.
Textbook:
References Oracle Press (2010). Applied Oracle Security
References:
Pratt, Philip J. (2010). Database management systems
Rob, Peter & Coronel, Carlo (2009). Database
Management Systems
Schwalbe, Kathy (2011). Management of Information
Technology Projects
Wheeler, Evan (2011). Security Risk Management :
Building an Information Security Risk Management
Program from the Ground Up
Supplementary Reading and Video Link
Supplementary Reading
https://www.w3schools.in/mysql/ddl-dml-dcl/
http://www.oracle-dba-
online.com/sql/oracle_data_definition_language.htm
https://www.tutorialspoint.com/sql_certificate/using_ddl_statem
ents.htm
Supplementary Video
https://www.youtube.com/watch?v=XIhAhXda6EE
https://www.youtube.com/watch?v=UvymdJ5IjZA
https://www.youtube.com/watch?v=5dszS8TxTJ4
Suggested Reading
SQL Tutorial. In ws3schools, Retrieved from
http://www.w3schools.com/sql/default.asp
Database management system. In Encyclopedia
Britannica, Retrieved from
http://www.britannica.com/EBchecked/topic/152201/
database-management-system-DBMS.
_____________________________________________________________________________________
14