Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

ASSIGNMENT -2

Components of SQL
SQL has 4 major components
 DDL (Data Definition Language)
 DML (Data Manipulation Language)
 DCL(Data Control Language)
 DQL (Data Query Language)

DDL (Data Definition Language)


DDL (Data Definition Language) : DDL or Data Definition Language actually
consists of the SQL commands that can be used to define the database schema. It simply
deals with descriptions of the database schema and is used to create and modify the
structure of database objects in the database.
Commands
 Create
 Alter
 Rename
 Drop
 Description
 Truncate
 Comment
Create Command
The Command is used to create the database objects like table, index, function , views,
store procedures and triggers.
Oracle table naming Standards
To simplify development, we will follow these rules that allow the developer to quickly
identify each metadata object, with complete descriptive names:
 Table Standards
 All table names will be plural (e.g. users vs. user).
 Full table names will be used whenever possible.
ASSIGNMENT -2

 If a table name should exceed 30 characters, reduce the size of the table name in
this order:

 From the left of the table name, remove vowels from each word in the table
name except for the first vowel of each word.

 If the table name is still greater than 30 characters, use standardized


shorthand indicators. Record this standard for consistent use.
Oracle column naming Standards

 Column Naming Standards

 Column names should be spelled out whenever possible.

 If a column name should exceed 30 characters, reduce the size of the column name
in this order:

 From the left of the column name, remove vowels from each word in the table
name except for the first vowel of each word.

 If the column name is still greater than 30 characters, use standardized


shorthand indicators. Record this standard for consistent use.
 Must begain with a letter
 Must be 1-3- character long
 Must contain only A-Z,a-z,0-9,_
 Must not duplicate the names of another object owened by the same user. Must
not be an oracle server reserved word.
Oracle Data Types
CHAR(size) It is used to store character data within the predefined length. It
can be stored up to 2000 bytes.
VARCHAR2(size) It is used to store variable string data within the predefined length.
It can be stored up to 4000 byte.
VARCHAR(SIZE) It is the same as VARCHAR2(size). You can also use
VARCHAR(size), but it is suggested to use VARCHAR2(size)
NUMBER(p, s) It contains precision p and scale s. The precision p can range from
1 to 38, and the scale s can range from -84 to 127.
ASSIGNMENT -2

FLOAT(p) It is a subtype of the NUMBER data type. The precision p can


range from 1 to 126.
DATE It is used to store a valid date-time format with a fixed length. Its
range varies from January 1, 4712 BC to December 31, 9999 AD.
TIMESTAMP It is used to store the valid date in YYYY-MM-DD with time
hh:mm:ss format.

SYNTAX
CREATE TABLE table_name(column1 datatype,column2 datatype,
column3 datatype, ..... columnN datatype );

Example
CREATE TABLE STUDENTS
(
REGNO CHAR(4),
FIRST_NAME VARCHAR2(15),
LAST_NAME VARCHAR2(15),
DOB DATE,
BRANCH VARCHAR2(3),
SUBJECT VARCHAR2(3),
MARK NUMBER(3)
);
DISPLAY THE STRUCTURE OF TABLE
SYNTAX
DESC <TABLENAME>
Example
DESC STUDENTS

ALTER COMMAND:
Alter table command is used to alter the structure of the table Operation performed with
table.
ASSIGNMENT -2

 Add new column


SYNTAX
ALTER TABLE table_name ADD column_name datatype;
Example
Alter table student add address varchar2 (50)

 Modify existing column


SYNTAX
ALTER TABLE table_name MODIFY COLUMN column_name datatype;
Example
Alter table student modify address varchar2 (50)

 Drop column
SYNTAX
ALTER TABLE table_name DROP COLUMN <COLUMN NAME>;
Example
Alter table employee drop column Branch;

 Drop multiple column


Alter table cities drop (state,pin);

 Rename column
SYNTAX
Alter tablename rename column <column_name_old> to <column_name_new>;
Example
Alter table student rename column address to address1;
RENAME COMMAND
The rename command is used to rename the existing table from the database.
SYNTAX
Rename mytable to newtable;
Example
Rename Student to Student_Details
ASSIGNMENT -2

DROP COMMAND
The command is used to delete the table and its description.
SYNTAX
Drop table tablename;
Example
Drop table Student_Details;
TRUNCATE COMMAND
The command is used to delete the table and its description with its memory.
SYNTAX
Truncate table tablename;
Example
Truncate table Student_Details;
COMMENT COMMAND
The command is used to add comment to the data dictionary.
SYNTAX
--single line comment
Example
-- alter table can be possible with rename and delete any specific column

SYNTAX
/* multi line comment
any other comment*/
ASSIGNMENT -2
ASSIGNMENT -2
ASSIGNMENT -2

You might also like