SQL-DDL and DML
SQL-DDL and DML
Management Systems
Structured Query Language
Dr. K.P. Vijayakumar
VIT Chennai
Introduction
SQL stands for Structured Query Language.
SEQUEL (Structured English Query
Language)
Allows to create, access and manipulate
databases
American National Standards Institute
(ANSI) and International Organization for
Standardization (ISO)
SQL 86 or SQL1
SQL 92 or SQL2
SQL 1999 – SQL3
SQL 2003, SQL 2006, SQL 2008, SQL 2011,
SQL 2016, SQL 2019
Schema, Catalog
Database - Table
Schema
Structure of the table
Structure of data
Catalog
contains a special schema
Information of all the schemas
Meta data, Data Dictionary
data about data
Data Types
Data types defines the type of value to
be stored in the table.
SQL data types can be broadly divided
into following categories.
Numeric data types
Date and Time data types
Character and String data types
Bit string -BIT(n)
Boolean
Miscellaneous data types – clob, blob, xml, cursor,
table etc.
Data Types
Numeric data types
Number(n), Number(n,m), Decimal(n,m),
int, float
n – no. of digits in a number. It ranges from
1 to 38
m - no. of digits to the right of the decimal
point . It ranges from -84 to 127
Date and Time data types
DATE –YYYY- MM-DD,
TO_DATE ()
Data Types
Character and String data types
Char, Varchar,Varchar2
Char - 2000 bytes
Varchar, varchar2 - 4000 bytes
Bit string -BIT(n)
Boolean
Miscellaneous data types – clob, blob,
xml, cursor, table etc.
DDL, DML, TCL & DCL
Data Definition Language
Data Manipulation Language
Transaction Control Language
Data Control Language
DDL, DML, TCL & DCL
SQL Commands
RENAME DELETE
TRUNCATE
DDL, DML, TCL & DCL
DDL Command :
CREATE
Syntax
CREATE TABLE table_name ( column1 datatype, column2 datatype, column3
datatype, .... );
Example
Create table Student(Name varchar2(20), Regno number,Year number);
Syntax:
Department
ALTER TABLE table_name ADD column_name datatype;
Example
Alter table Student add dept varchar2(10);
DDL, DML, TCL & DCL
ALTER
To modify existing column
Syntax:
ALTER TABLE table_name MODIFY column_name datatype;
Varchar2(10)
Example
Alter table Student modify regno varchar2(10);
DDL, DML, TCL & DCL
ALTER
To drop existing column
Syntax:
ALTER TABLE table_name DROP COLUMN column_name ;
Example
Alter table Student drop column year;
DDL, DML, TCL & DCL
Student
ALTER
To rename the table
Syntax:
ALTER TABLE table_name RENAME TO new_table_name ;
Students
Example
Alter table Student RENAME TO Students;
DDL, DML, TCL & DCL
ALTER
To rename existing column
Syntax:
ALTER TABLE table_name RENAME COLUMN Old_column_name To
New_column_name;
Example
Alter table Student RENAME COLUMN regno TO registration;
DDL, DML, TCL & DCL
DROP – table structure will be removed
Syntax
DROP TABLE table_name;
Example
DROP TABLE Student;