SlideShare a Scribd company logo
1 of 20
LECTURE -3
S T R U C T U R E D Q U E R Y L A N G U A G E
D A T A D E F I N I T I O N L A N G U A G E ( D D L )
D e l i v e r e d B y :
M r . S h u b h a m S h u k l a
DATA DEFINITION LANGUAGE (DDL):
Three basic commands:
• CREATE
• DROP
• ALTER
CREATE
• CREATE TABLE Statement
Syntax
CREATE TABLE table_name
(
column1 datatype [ NULL | NOT NULL ],
column2 datatype [ NULL | NOT NULL ],
...
column_n datatype [ NULL | NOT NULL ]
);
Example:
CREATE TABLE customers
(
customer_id number(10) NOT NULL,
customer_name varchar2(50) NOT NULL,
city varchar2(50),
PRIMARY KEY (customer_id)
);
CREATE TABLE AS Statement:
Create Table - By Copying all columns from another table
Syntax
CREATE TABLE new_table
AS (SELECT * FROM old_table);
Create Table - By Copying selected columns from another table
Syntax
CREATE TABLE new_table
AS (SELECT column_1, column2, ... column_n FROM old_table);
Create table - By Copying selected columns from multiple tables:
Syntax
CREATE TABLE new_table
AS (SELECT column_1, column2, ... column_n
FROM old_table_1, old_table_2, ... old_table_n);
Example:
CREATE TABLE sup_cust
AS (SELECT customers.customer_id, customers.city, Supplier1.Supplier_name
FROM customers, Supplier1
WHERE customers.customer_id = Supplier1.Supplier_id);
ALTER
• ALTER TABLE Statement
Add Single column in table
Syntax
ALTER TABLE table_name
ADD column_name column-definition;
Example:
ALTER TABLE customers
ADD customer_name varchar2(45);
Add multiple columns in table
Syntax
ALTER TABLE table_name
ADD (column_1 column-definition,
column_2 column-definition,
...
column_n column_definition);
For example:
ALTER TABLE customers
ADD (customer_name varchar2(45),
city varchar2(40));
Modify column in table
Syntax
ALTER TABLE table_name
MODIFY column_name column_type;
For example:
ALTER TABLE customers
MODIFY customer_name varchar2(100) not null;
Modify Multiple columns in table
Syntax
ALTER TABLE table_name
MODIFY (column_1 column_type,
column_2 column_type,
...
column_n column_type);
For example:
ALTER TABLE customers
MODIFY (customer_name varchar2(100) not null,
city varchar2(75));
Drop column in table
Syntax
ALTER TABLE table_name
DROP COLUMN column_name;
For example:
ALTER TABLE customers
DROP COLUMN customer_name;
Rename column in table
Syntax
ALTER TABLE table_name
RENAME COLUMN old_name to new_name;
For example:
ALTER TABLE customers
RENAME COLUMN customer_name to cname;
Rename table
Syntax
ALTER TABLE table_name
RENAME TO new_table_name;
For example:
ALTER TABLE customers
RENAME TO contacts;
DROP
DROP TABLE Statement
Syntax
DROP TABLE [schema_name].table_name
[ CASCADE CONSTRAINTS ]
[ PURGE ];
CASCADE CONSTRAINTS: Optional. If specified, all referential integrity constraints will
be dropped as well.
PURGE: Optional. If specified, the table and its dependent objects will be purged from the
recycle bin and you will not be able to recover the table. If not specified, the table and its
dependent objects are placed in the recycle bin and can be recovered later, if needed.
For example:
DROP TABLE customers PURGE;
VIEW
• It is a virtual table that does not physically exist. Rather, it is created by a
query joining one or more tables.
Create VIEW
Syntax
CREATE VIEW view_name AS
SELECT columns
FROM tables
[WHERE conditions];
VIEW
Example:
CREATE VIEW sup_orders AS
SELECT suppliers.supplier_id, orders.quantity, orders.price
FROM suppliers
INNER JOIN orders
ON suppliers.supplier_id = orders.supplier_id
WHERE suppliers.supplier_name = 'Microsoft';
Update VIEW
Syntax
CREATE OR REPLACE VIEW view_name AS
SELECT columns
FROM table
WHERE conditions;
Example
CREATE or REPLACE VIEW sup_orders AS
SELECT suppliers.supplier_id, orders.quantity, orders.price
FROM suppliers
INNER JOIN orders
ON suppliers.supplier_id = orders.supplier_id
WHERE suppliers.supplier_name = 'Apple';
Drop VIEW
Syntax
DROP VIEW view_name;
Example
DROP VIEW sup_orders;
THANK YOU

More Related Content

What's hot

What's hot (19)

SQL
SQLSQL
SQL
 
Bibashsql
BibashsqlBibashsql
Bibashsql
 
Sql reference from w3 schools
Sql reference from w3 schools Sql reference from w3 schools
Sql reference from w3 schools
 
Select To Order By
Select  To  Order BySelect  To  Order By
Select To Order By
 
Commands
CommandsCommands
Commands
 
Les02
Les02Les02
Les02
 
Oracle: PLSQL Commands
Oracle: PLSQL CommandsOracle: PLSQL Commands
Oracle: PLSQL Commands
 
Database Management - Lecture 2 - SQL select, insert, update and delete
Database Management - Lecture 2 - SQL select, insert, update and deleteDatabase Management - Lecture 2 - SQL select, insert, update and delete
Database Management - Lecture 2 - SQL select, insert, update and delete
 
Database Systems - SQL - DDL Statements (Chapter 3/2)
Database Systems - SQL - DDL Statements (Chapter 3/2)Database Systems - SQL - DDL Statements (Chapter 3/2)
Database Systems - SQL - DDL Statements (Chapter 3/2)
 
Sql
SqlSql
Sql
 
Oracle: DDL
Oracle: DDLOracle: DDL
Oracle: DDL
 
Mysql Statments
Mysql StatmentsMysql Statments
Mysql Statments
 
Sql
SqlSql
Sql
 
DATABASE CONSTRAINTS
DATABASE CONSTRAINTSDATABASE CONSTRAINTS
DATABASE CONSTRAINTS
 
Ppt INFORMATIVE PRACTICES for class 11th chapter 14
Ppt INFORMATIVE PRACTICES for class 11th chapter 14Ppt INFORMATIVE PRACTICES for class 11th chapter 14
Ppt INFORMATIVE PRACTICES for class 11th chapter 14
 
Oracle: DML
Oracle: DMLOracle: DML
Oracle: DML
 
SQL Tutorial for Beginners
SQL Tutorial for BeginnersSQL Tutorial for Beginners
SQL Tutorial for Beginners
 
Data Definition Language (DDL)
Data Definition Language (DDL) Data Definition Language (DDL)
Data Definition Language (DDL)
 
06.01 sql select distinct
06.01 sql select distinct06.01 sql select distinct
06.01 sql select distinct
 

Similar to Lecture 3 sql {basics ddl commands}

Similar to Lecture 3 sql {basics ddl commands} (20)

Oraclesql
OraclesqlOraclesql
Oraclesql
 
SQL - DML and DDL Commands
SQL - DML and DDL CommandsSQL - DML and DDL Commands
SQL - DML and DDL Commands
 
Sqlbysandeep
SqlbysandeepSqlbysandeep
Sqlbysandeep
 
Les10 Creating And Managing Tables
Les10 Creating And Managing TablesLes10 Creating And Managing Tables
Les10 Creating And Managing Tables
 
Les09 (using ddl statements to create and manage tables)
Les09 (using ddl statements to create and manage tables)Les09 (using ddl statements to create and manage tables)
Les09 (using ddl statements to create and manage tables)
 
Les09
Les09Les09
Les09
 
Introduction to sql new
Introduction to sql newIntroduction to sql new
Introduction to sql new
 
Basic sql Commands
Basic sql CommandsBasic sql Commands
Basic sql Commands
 
Les10
Les10Les10
Les10
 
Module4.4_DDL_DML_DCL_ for beginners .pptx
Module4.4_DDL_DML_DCL_ for beginners .pptxModule4.4_DDL_DML_DCL_ for beginners .pptx
Module4.4_DDL_DML_DCL_ for beginners .pptx
 
Sql
SqlSql
Sql
 
COMPUTERS SQL
COMPUTERS SQL COMPUTERS SQL
COMPUTERS SQL
 
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
 
Sql cheat sheet
Sql cheat sheetSql cheat sheet
Sql cheat sheet
 
Using ddl statements to create and manage tables
Using ddl statements to create and manage tablesUsing ddl statements to create and manage tables
Using ddl statements to create and manage tables
 
SQL : Structured Query Language
SQL : Structured Query LanguageSQL : Structured Query Language
SQL : Structured Query Language
 
dbms.pdf
dbms.pdfdbms.pdf
dbms.pdf
 
Creating a database
Creating a databaseCreating a database
Creating a database
 
SQL
SQLSQL
SQL
 
MySQL Database System Hiep Dinh
MySQL Database System Hiep DinhMySQL Database System Hiep Dinh
MySQL Database System Hiep Dinh
 

Recently uploaded

Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonJericReyAuditor
 

Recently uploaded (20)

Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lesson
 

Lecture 3 sql {basics ddl commands}

  • 1. LECTURE -3 S T R U C T U R E D Q U E R Y L A N G U A G E D A T A D E F I N I T I O N L A N G U A G E ( D D L ) D e l i v e r e d B y : M r . S h u b h a m S h u k l a
  • 2. DATA DEFINITION LANGUAGE (DDL): Three basic commands: • CREATE • DROP • ALTER
  • 3. CREATE • CREATE TABLE Statement Syntax CREATE TABLE table_name ( column1 datatype [ NULL | NOT NULL ], column2 datatype [ NULL | NOT NULL ], ... column_n datatype [ NULL | NOT NULL ] );
  • 4. Example: CREATE TABLE customers ( customer_id number(10) NOT NULL, customer_name varchar2(50) NOT NULL, city varchar2(50), PRIMARY KEY (customer_id) );
  • 5. CREATE TABLE AS Statement: Create Table - By Copying all columns from another table Syntax CREATE TABLE new_table AS (SELECT * FROM old_table); Create Table - By Copying selected columns from another table Syntax CREATE TABLE new_table AS (SELECT column_1, column2, ... column_n FROM old_table);
  • 6. Create table - By Copying selected columns from multiple tables: Syntax CREATE TABLE new_table AS (SELECT column_1, column2, ... column_n FROM old_table_1, old_table_2, ... old_table_n); Example: CREATE TABLE sup_cust AS (SELECT customers.customer_id, customers.city, Supplier1.Supplier_name FROM customers, Supplier1 WHERE customers.customer_id = Supplier1.Supplier_id);
  • 7. ALTER • ALTER TABLE Statement Add Single column in table Syntax ALTER TABLE table_name ADD column_name column-definition; Example: ALTER TABLE customers ADD customer_name varchar2(45);
  • 8. Add multiple columns in table Syntax ALTER TABLE table_name ADD (column_1 column-definition, column_2 column-definition, ... column_n column_definition); For example: ALTER TABLE customers ADD (customer_name varchar2(45), city varchar2(40));
  • 9. Modify column in table Syntax ALTER TABLE table_name MODIFY column_name column_type; For example: ALTER TABLE customers MODIFY customer_name varchar2(100) not null;
  • 10. Modify Multiple columns in table Syntax ALTER TABLE table_name MODIFY (column_1 column_type, column_2 column_type, ... column_n column_type); For example: ALTER TABLE customers MODIFY (customer_name varchar2(100) not null, city varchar2(75));
  • 11. Drop column in table Syntax ALTER TABLE table_name DROP COLUMN column_name; For example: ALTER TABLE customers DROP COLUMN customer_name;
  • 12. Rename column in table Syntax ALTER TABLE table_name RENAME COLUMN old_name to new_name; For example: ALTER TABLE customers RENAME COLUMN customer_name to cname;
  • 13. Rename table Syntax ALTER TABLE table_name RENAME TO new_table_name; For example: ALTER TABLE customers RENAME TO contacts;
  • 14. DROP DROP TABLE Statement Syntax DROP TABLE [schema_name].table_name [ CASCADE CONSTRAINTS ] [ PURGE ]; CASCADE CONSTRAINTS: Optional. If specified, all referential integrity constraints will be dropped as well. PURGE: Optional. If specified, the table and its dependent objects will be purged from the recycle bin and you will not be able to recover the table. If not specified, the table and its dependent objects are placed in the recycle bin and can be recovered later, if needed. For example: DROP TABLE customers PURGE;
  • 15. VIEW • It is a virtual table that does not physically exist. Rather, it is created by a query joining one or more tables. Create VIEW Syntax CREATE VIEW view_name AS SELECT columns FROM tables [WHERE conditions];
  • 16. VIEW Example: CREATE VIEW sup_orders AS SELECT suppliers.supplier_id, orders.quantity, orders.price FROM suppliers INNER JOIN orders ON suppliers.supplier_id = orders.supplier_id WHERE suppliers.supplier_name = 'Microsoft';
  • 17. Update VIEW Syntax CREATE OR REPLACE VIEW view_name AS SELECT columns FROM table WHERE conditions;
  • 18. Example CREATE or REPLACE VIEW sup_orders AS SELECT suppliers.supplier_id, orders.quantity, orders.price FROM suppliers INNER JOIN orders ON suppliers.supplier_id = orders.supplier_id WHERE suppliers.supplier_name = 'Apple';
  • 19. Drop VIEW Syntax DROP VIEW view_name; Example DROP VIEW sup_orders;