SlideShare a Scribd company logo
1 of 62
Query
 A Language which is used to store and retrieve data from database is
known as query language. For example – SQL
 There are two types of query language:
1.Procedural Query language
2.Non-procedural query language
Nahida Nazir
Procedural Query language
 In procedural query language, user instructs the system to perform a
series of operations to produce the desired results. Here users tells
what data to be retrieved from database and how to retrieve it.
Nahida Nazir
Non-procedural query language:
 n Non-procedural query language, user instructs the system to
produce the desired result without telling the step by step process.
Here users tells what data to be retrieved from database but doesn’t
tell how to retrieve it.
Nahida Nazir
Relational Algebra:
 Relational algebra is a conceptual procedural query language used on relational model
 Relational Calculus:
 Relational calculus is a conceptual non-procedural query language used on relational
model.
 SQL is a practical implementation of relational algebra and relational calculus.
Nahida Nazir
Relational Algebra
 Relational algebra is a procedural query language that works on relational model. The
purpose of a query language is to retrieve data from database or perform various
operations such as insert, update, delete on the data.
Nahida Nazir
Types of operations in relational
algebra
 1. Basic Operations
2. Derived Operations
Nahida Nazir
Basic/Fundamental Operations:
 1. Select (σ)
2. Project (∏)
3. Union (∪)
4. Set Difference (-)
5. Cartesian product (X)
6. Rename (ρ)
Nahida Nazir
Derived Operations:
 1. Natural Join (⋈)
2. Left, Right, Full outer join (⟕, ⟖, ⟗)
3. Intersection (∩)
4. Division (÷)
Nahida Nazir
Select Operator (σ)
 Select Operator is denoted by sigma (σ) and it is used to find the tuples (or rows)
in a relation (or table) which satisfy the given condition.
 Predicates are keywords that specify a relationship between two expressions.
 Syntax: σ Condition/Predicate(Relation/Table name)
Nahida Nazir
Example
Nahida Nazir
Project Operator (∏)
 Project operator is denoted by ∏ symbol and it is used to select desired
columns (or attributes) from a table (or relation).
 Syntax of Project Operator (∏)
 ∏ column_name1, column_name2, ...., column_nameN(table_name)
Nahida Nazir
Example
Nahida Nazir
Union Operator (∪)
 Union operator is denoted by ∪ symbol and it is used to select all the
rows (tuples) from two tables (relations).
 Lets say we have two relations R1 and R2 both have same columns and we want to select
all the tuples(rows) from these relations then we can apply the union operator on these
relations.
 Note: The rows (tuples) that are present in both the tables will only appear once in the union
set. In short you can say that there are no duplicates present after the union operation.
 There are no duplicate names present in the output
 Syntax of Union Operator (∪)
 table_name1 ∪ table_name2
Nahida Nazir
Intersection Operator (∩)
 Intersection operator is denoted by ∩ symbol and it is used to select common rows
(tuples) from two tables (relations).
 Lets say we have two relations R1 and R2 both have same columns and we want to
select all those tuples(rows) that are present in both the relations, then in that case
we can apply intersection operation on these two relations R1 ∩ R2.
 Note: Only those rows that are present in both the tables will appear in the result set.
 Syntax of Intersection Operator (∩)
 table_name1 ∩ table_name2
Nahida Nazir
Set Difference (-)
 Set Difference is denoted by – symbol. Lets say we have two relations R1 and
R2 and we want to select all those tuples(rows) that are present in Relation R1
but not present in Relation R2, this can be done using Set difference R1 – R2.
 Syntax of Set Difference (-)
 table_name1 - table_name2
Nahida Nazir
Cartesian product (X)
 Cartesian Product is denoted by X symbol. Lets say we have two relations R1 and
R2 then the cartesian product of these two relations (R1 X R2) would combine each
tuple of first relation R1 with the each tuple of second relation R2. I know it sounds
confusing but once we take an example of this, you will be able to understand this.
 Syntax of Cartesian product (X)
 R1 X R2
Nahida Nazir
Rename (ρ)
 Rename (ρ) operation can be used to rename a relation or an attribute of a
relation.
Rename (ρ) Syntax:
ρ(new_relation_name, old_relation_name)
Nahida Nazir
What is SQL?
SQL stands for Structured Query Language.
SQL is used to communicate with a database.
SQL lets you access and manipulate databases.
Software to be used: Oracle
Nahida Nazir
Polling Question
Nahida Nazir
What SQL can do?
What Can SQL do?
-SQL can execute queries against a database
-SQL can retrieve data from a database
-SQL can insert records in a database
-SQL can update records in a database
-SQL can delete records from a database
-SQL can create new databases
-SQL can create new tables in a database
-SQL can create stored procedures in a database
-SQL can create views in a database
-SQL can set permissions on tables, procedures, and views
Nahida Nazir
DDL
Data Definition Language (DDL) statements are used to define the database
structure or schema. Some examples:
•CREATE - to create objects in the database
•ALTER - alters the structure of the database
•DROP - delete objects from the database
•TRUNCATE - remove all records from a table, including all spaces allocated
for the records are removed
•RENAME - rename an object
Nahida Nazir
DML
Data Manipulation Language (DML) statements are used for managing data
within schema objects. Some examples:
•SELECT - retrieve data from the a database
•INSERT - insert data into a table
•UPDATE - updates existing data within a table
•DELETE - deletes all records from a table, the space for the records remain
Nahida Nazir
CREATING A TABLE
The CREATE TABLE statement is used to create a table in a database.
Tables are organized into rows and columns; and each table must have a
name.
Nahida Nazir
CREATING A TABLE
Syntax:
CREATE TABLE table_name
(
column_name1 data_type(size),
column_name2 data_type(size),
column_name3 data_type(size),
....
);
Nahida Nazir
CREATING A TABLE
Example:
CREATE TABLE Student
(
StudentID int,
LastName varchar(25),
FirstName varchar(25),
CGPA float,
Address varchar(25)
);
Nahida Nazir
Describe table
Nahida Nazir
INSERTING INTO A
TABLE
The INSERT INTO statement is used to insert new records or rows in a table.
It is possible to write the INSERT INTO statement in two forms.
Nahida Nazir
Inserting first row
Nahida Nazir
Inserting 2nd Row
Nahida Nazir
Inserting 3rd Row
Nahida Nazir
Select command
Nahida Nazir
Nahida Nazir
Union
Nahida Nazir
INSERTING INTO A
TABLE
The first form does not specify the column names where the data will be
inserted, only their values:
Syntax:
INSERT INTO table_name
VALUES (value1,value2,value3,...);
Nahida Nazir
INSERTING INTO A
TABLE
Example:
INSERT INTO Student VALUES (1, ‘Kumar’, ‘Ravi’, 8.7, ‘Jal’ );
INSERT INTO Student VALUES (2, ‘Sharma’, ‘Partha’, 6.8, ‘Phagwara’);
INSERT INTO Student VALUES (3, ‘Singh’, ‘Gurpreet’, 9.5, ‘Ldh’ );
INSERT INTO Student VALUES (4, ‘Jain’, ‘Neharika’, 7.2, Jal );
Nahida Nazir
INSERTING INTO A
TABLE
The second form specifies both the column names and the values to be
inserted
Syntax:
INSERT INTO table_name (column1,column2,column3,...)
VALUES (value1,value2,value3,...);
Nahida Nazir
INSERTING INTO A
TABLE
Example:
INSERT INTO Student (StudentID, FirstName, CGPA) VALUES (1, ‘Ravi’, 8.7);
INSERT INTO Student (StudentID, FirstName, CGPA) VALUES (2, ‘Partha’, 6.8);
INSERT INTO Student (StudentID, FirstName, CGPA) VALUES (3, ‘Gurpreet’,
9.5);
INSERT INTO Student (StudentID, FirstName, CGPA) VALUES (4, ‘Neharika’,
7.2);
Nahida Nazir
SELECT STATEMENT
The SELECT statement is used to select data from a database.
For retrieving all the columns and rows:
Syntax
SELECT * FROM table_name;
Example
Ques: Show the records of all the students from ‘Student’ table.
Ans.
SELECT * FROM Student;
Nahida Nazir
 create table ki(id int, roll_no int, salary float, address
varchar(20));
 insert into ki values(21, 56,67.89, 'hj');
 select*from ki;
 alter table ki add email varchar(23);
ALTER TABLE ki
DROP COLUMN Email;
 update ki set email='nahida@12.gmail.com’
Nahida Nazir
create table ki(id int, roll_no int, salary float, address
varchar(20));
insert into ki values(21, 56,67.89, 'hj');
select*from ki;
alter table ki add try varchar(23);
ALTER TABLE Customers
DROP COLUMN Email;
update ki set try='89' where id=21;
Nahida Nazir
SELECT STATEMENT
For retrieving specific columns:
Syntax
SELECT column_name1, column_name2
FROM table_name;
Example
Ques: Show the columns StudentID, LastName and City from ‘Student’
table.
Ans.
SELECT StudentID, LastName, City
FROM Student;
Nahida Nazir
SELECT STATEMENT
For retrieving records using condition:
Syntax
SELECT *
FROM table_name
WHERE condition;
Example
Ques: Show record of student having StudentID=2 from ‘Student’ table.
Ans.
SELECT *
FROM Student
WHERE StudentID=2;
Nahida Nazir
UPDATING A TABLE
The SQL UPDATE Query is used to modify the existing records in a table.
You can use WHERE clause with UPDATE query to update selected rows
otherwise all the rows would be affected.
Syntax
UPDATE table_name
SET column1=value1, column2=value2,...
WHERE some_column=some_value;
Nahida Nazir
UPDATING A TABLE
Example
Ques: Update Lastname of student having StudentID=4 .
Ans.
UPDATE Student
SET LastName = ‘Verma’
WHERE StudentID = 4;
Ques: Update Address of all the students.
Ans.
UPDATE Student
SET Address = ‘Jal’;
Ques: Update CGPA of student having StudentID=3.
Ans.
UPDATE Student
SET CGPA = 9.7
WHERE StudentID = 3;
Nahida Nazir
Update
Nahida Nazir
Updated Single Value
Nahida Nazir
Updated multiple values
Nahida Nazir
ALTERING A TABLE
The ALTER TABLE statement is used to add, delete, or modify columns in an
existing table.
Syntax
To add a column:
ALTER TABLE table_name
ADD column_name datatype;
To delete a column:
ALTER TABLE table_name
DROP COLUMN column_name;
Nahida Nazir
Alter table
Nahida Nazir
DELETING FROM TABLE
The SQL DELETE Query is used to delete the existing records from a
table.
You can use WHERE clause with DELETE query to delete selected rows,
otherwise all the records would be deleted.
Syntax
DELETE FROM table_name
WHERE some_column=some_value;
Nahida Nazir
DELETING FROM TABLE
Example
Ques: Delete the record of student having StudentID=2.
Ans.
DELETE FROM Student
WHERE StudentID=2;
Ques: Delete the records of all students living in ‘Jalandhar’.
Ans.
DELETE FROM Student
WHERE Address=‘Jal’;
Ques: Delete the records of all the students.
Ans.
DELETE FROM Student;
Nahida Nazir
ALTERING A TABLE
Example
Ques: Add a column FathersName into ‘Student’ table.
Ans.
ALTER TABLE Student
ADD FathersName varchar(30);
Ques: Delete column Address from ‘Student’ table.
Ans.
ALTER TABLE Student
DROP COLUMN Address;
Nahida Nazir
Altering a table
Nahida Nazir
Inserting data into created
columns
Nahida Nazir
RENAMING A COLUMN
Syntax
rename ki to ui;
ALTER TABLE table_name
RENAME COLUMN column1 TO column2;
Example
Ques: Change name of the column StudentID to ID.
Ans.
ALTER TABLE Student
RENAME COLUMN StudentID TO ID;
Nahida Nazir
DROP TABLE
The SQL DROP TABLE statement is used to remove a table definition and all
data, triggers, constraints, and permission specifications for that table.
NOTE: You have to be careful while using this command because once a table
is deleted then all the information available in the table would also be lost
forever.
Nahida Nazir
DROP TABLE
Syntax
DROP TABLE table_name;
Example
Ques: Drop the ‘Student’ table.
Ans.
DROP TABLE Student;
Nahida Nazir
Delete syntax
 delete from ui where id=21;
Nahida Nazir
TRUNCATE TABLE
The SQL TRUNCATE TABLE command is used to delete complete data from an
existing table.
You can also use DROP TABLE command to delete complete table but it would
remove complete table structure form the database and you would need to
re-create this table once again if you wish you store some data.
Nahida Nazir
TRUNCATE TABLE
Syntax
TRUNCATE TABLE table_name;
Example
Ques: Truncate the ‘Student’ table.
Ans.
TRUNCATE TABLE Student;
Nahida Nazir
Difference among
DELETE, DROP, and
TRUNCATE
DELETE:
The DELETE command is used to remove rows from a table.
A WHERE clause can be used to only remove some rows. If no WHERE
condition is specified, all rows will be removed.
After performing a DELETE operation you need to COMMIT or ROLLBACK the
transaction to make the change permanent or to undo it.
Note that this operation will cause all DELETE triggers on the table to fire.
Nahida Nazir
Difference among
DELETE, DROP, and
TRUNCATE
TRUNCATE:
TRUNCATE removes all rows from a table. The operation cannot be rolled
back and no triggers will be fired. As such, TRUNCATE is faster.
DROP:
The DROP command removes a table from the database. All the tables' rows,
indexes and privileges will also be removed. No DML triggers will be fired.
The operation cannot be rolled back.
Nahida Nazir

More Related Content

Similar to DDL and DML statements.pptx

Similar to DDL and DML statements.pptx (20)

Sql 
statements , functions & joins
Sql 
statements , functions  &  joinsSql 
statements , functions  &  joins
Sql 
statements , functions & joins
 
Lab
LabLab
Lab
 
SQL
SQLSQL
SQL
 
ch3.ppt
ch3.pptch3.ppt
ch3.ppt
 
BCS4L1-Database Management lab.pdf
BCS4L1-Database Management lab.pdfBCS4L1-Database Management lab.pdf
BCS4L1-Database Management lab.pdf
 
Data Manipulation Language.pptx
Data Manipulation Language.pptxData Manipulation Language.pptx
Data Manipulation Language.pptx
 
SQL Overview
SQL OverviewSQL Overview
SQL Overview
 
Statements,joins and operators in sql by thanveer danish melayi(1)
Statements,joins and operators in sql by thanveer danish melayi(1)Statements,joins and operators in sql by thanveer danish melayi(1)
Statements,joins and operators in sql by thanveer danish melayi(1)
 
Query
QueryQuery
Query
 
Les09
Les09Les09
Les09
 
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)
 
Database COMPLETE
Database COMPLETEDatabase COMPLETE
Database COMPLETE
 
12 SQL
12 SQL12 SQL
12 SQL
 
12 SQL
12 SQL12 SQL
12 SQL
 
Sql overview-1232931296681161-1
Sql overview-1232931296681161-1Sql overview-1232931296681161-1
Sql overview-1232931296681161-1
 
Its about a sql topic for basic structured query language
Its about a sql topic for basic structured query languageIts about a sql topic for basic structured query language
Its about a sql topic for basic structured query language
 
ch3.ppt
ch3.pptch3.ppt
ch3.ppt
 
Introduction to SQL
Introduction to SQLIntroduction to SQL
Introduction to SQL
 
ch3.ppt
ch3.pptch3.ppt
ch3.ppt
 
ch3.ppt
ch3.pptch3.ppt
ch3.ppt
 

More from Karthick Panneerselvam (6)

Cursors.ppt
Cursors.pptCursors.ppt
Cursors.ppt
 
Concurrent Transactions.ppt
Concurrent Transactions.pptConcurrent Transactions.ppt
Concurrent Transactions.ppt
 
Risk Analysis.pptx
Risk Analysis.pptxRisk Analysis.pptx
Risk Analysis.pptx
 
standards1.pdf
standards1.pdfstandards1.pdf
standards1.pdf
 
Security.pdf
Security.pdfSecurity.pdf
Security.pdf
 
computer Network
computer Networkcomputer Network
computer Network
 

Recently uploaded

Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLDeelipZope
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2RajaP95
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
microprocessor 8085 and its interfacing
microprocessor 8085  and its interfacingmicroprocessor 8085  and its interfacing
microprocessor 8085 and its interfacingjaychoudhary37
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 

Recently uploaded (20)

Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCL
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
microprocessor 8085 and its interfacing
microprocessor 8085  and its interfacingmicroprocessor 8085  and its interfacing
microprocessor 8085 and its interfacing
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 

DDL and DML statements.pptx

  • 1. Query  A Language which is used to store and retrieve data from database is known as query language. For example – SQL  There are two types of query language: 1.Procedural Query language 2.Non-procedural query language Nahida Nazir
  • 2. Procedural Query language  In procedural query language, user instructs the system to perform a series of operations to produce the desired results. Here users tells what data to be retrieved from database and how to retrieve it. Nahida Nazir
  • 3. Non-procedural query language:  n Non-procedural query language, user instructs the system to produce the desired result without telling the step by step process. Here users tells what data to be retrieved from database but doesn’t tell how to retrieve it. Nahida Nazir
  • 4. Relational Algebra:  Relational algebra is a conceptual procedural query language used on relational model  Relational Calculus:  Relational calculus is a conceptual non-procedural query language used on relational model.  SQL is a practical implementation of relational algebra and relational calculus. Nahida Nazir
  • 5. Relational Algebra  Relational algebra is a procedural query language that works on relational model. The purpose of a query language is to retrieve data from database or perform various operations such as insert, update, delete on the data. Nahida Nazir
  • 6. Types of operations in relational algebra  1. Basic Operations 2. Derived Operations Nahida Nazir
  • 7. Basic/Fundamental Operations:  1. Select (σ) 2. Project (∏) 3. Union (∪) 4. Set Difference (-) 5. Cartesian product (X) 6. Rename (ρ) Nahida Nazir
  • 8. Derived Operations:  1. Natural Join (⋈) 2. Left, Right, Full outer join (⟕, ⟖, ⟗) 3. Intersection (∩) 4. Division (÷) Nahida Nazir
  • 9. Select Operator (σ)  Select Operator is denoted by sigma (σ) and it is used to find the tuples (or rows) in a relation (or table) which satisfy the given condition.  Predicates are keywords that specify a relationship between two expressions.  Syntax: σ Condition/Predicate(Relation/Table name) Nahida Nazir
  • 11. Project Operator (∏)  Project operator is denoted by ∏ symbol and it is used to select desired columns (or attributes) from a table (or relation).  Syntax of Project Operator (∏)  ∏ column_name1, column_name2, ...., column_nameN(table_name) Nahida Nazir
  • 13. Union Operator (∪)  Union operator is denoted by ∪ symbol and it is used to select all the rows (tuples) from two tables (relations).  Lets say we have two relations R1 and R2 both have same columns and we want to select all the tuples(rows) from these relations then we can apply the union operator on these relations.  Note: The rows (tuples) that are present in both the tables will only appear once in the union set. In short you can say that there are no duplicates present after the union operation.  There are no duplicate names present in the output  Syntax of Union Operator (∪)  table_name1 ∪ table_name2 Nahida Nazir
  • 14. Intersection Operator (∩)  Intersection operator is denoted by ∩ symbol and it is used to select common rows (tuples) from two tables (relations).  Lets say we have two relations R1 and R2 both have same columns and we want to select all those tuples(rows) that are present in both the relations, then in that case we can apply intersection operation on these two relations R1 ∩ R2.  Note: Only those rows that are present in both the tables will appear in the result set.  Syntax of Intersection Operator (∩)  table_name1 ∩ table_name2 Nahida Nazir
  • 15. Set Difference (-)  Set Difference is denoted by – symbol. Lets say we have two relations R1 and R2 and we want to select all those tuples(rows) that are present in Relation R1 but not present in Relation R2, this can be done using Set difference R1 – R2.  Syntax of Set Difference (-)  table_name1 - table_name2 Nahida Nazir
  • 16. Cartesian product (X)  Cartesian Product is denoted by X symbol. Lets say we have two relations R1 and R2 then the cartesian product of these two relations (R1 X R2) would combine each tuple of first relation R1 with the each tuple of second relation R2. I know it sounds confusing but once we take an example of this, you will be able to understand this.  Syntax of Cartesian product (X)  R1 X R2 Nahida Nazir
  • 17. Rename (ρ)  Rename (ρ) operation can be used to rename a relation or an attribute of a relation. Rename (ρ) Syntax: ρ(new_relation_name, old_relation_name) Nahida Nazir
  • 18. What is SQL? SQL stands for Structured Query Language. SQL is used to communicate with a database. SQL lets you access and manipulate databases. Software to be used: Oracle Nahida Nazir
  • 20. What SQL can do? What Can SQL do? -SQL can execute queries against a database -SQL can retrieve data from a database -SQL can insert records in a database -SQL can update records in a database -SQL can delete records from a database -SQL can create new databases -SQL can create new tables in a database -SQL can create stored procedures in a database -SQL can create views in a database -SQL can set permissions on tables, procedures, and views Nahida Nazir
  • 21. DDL Data Definition Language (DDL) statements are used to define the database structure or schema. Some examples: •CREATE - to create objects in the database •ALTER - alters the structure of the database •DROP - delete objects from the database •TRUNCATE - remove all records from a table, including all spaces allocated for the records are removed •RENAME - rename an object Nahida Nazir
  • 22. DML Data Manipulation Language (DML) statements are used for managing data within schema objects. Some examples: •SELECT - retrieve data from the a database •INSERT - insert data into a table •UPDATE - updates existing data within a table •DELETE - deletes all records from a table, the space for the records remain Nahida Nazir
  • 23. CREATING A TABLE The CREATE TABLE statement is used to create a table in a database. Tables are organized into rows and columns; and each table must have a name. Nahida Nazir
  • 24. CREATING A TABLE Syntax: CREATE TABLE table_name ( column_name1 data_type(size), column_name2 data_type(size), column_name3 data_type(size), .... ); Nahida Nazir
  • 25. CREATING A TABLE Example: CREATE TABLE Student ( StudentID int, LastName varchar(25), FirstName varchar(25), CGPA float, Address varchar(25) ); Nahida Nazir
  • 27. INSERTING INTO A TABLE The INSERT INTO statement is used to insert new records or rows in a table. It is possible to write the INSERT INTO statement in two forms. Nahida Nazir
  • 34. INSERTING INTO A TABLE The first form does not specify the column names where the data will be inserted, only their values: Syntax: INSERT INTO table_name VALUES (value1,value2,value3,...); Nahida Nazir
  • 35. INSERTING INTO A TABLE Example: INSERT INTO Student VALUES (1, ‘Kumar’, ‘Ravi’, 8.7, ‘Jal’ ); INSERT INTO Student VALUES (2, ‘Sharma’, ‘Partha’, 6.8, ‘Phagwara’); INSERT INTO Student VALUES (3, ‘Singh’, ‘Gurpreet’, 9.5, ‘Ldh’ ); INSERT INTO Student VALUES (4, ‘Jain’, ‘Neharika’, 7.2, Jal ); Nahida Nazir
  • 36. INSERTING INTO A TABLE The second form specifies both the column names and the values to be inserted Syntax: INSERT INTO table_name (column1,column2,column3,...) VALUES (value1,value2,value3,...); Nahida Nazir
  • 37. INSERTING INTO A TABLE Example: INSERT INTO Student (StudentID, FirstName, CGPA) VALUES (1, ‘Ravi’, 8.7); INSERT INTO Student (StudentID, FirstName, CGPA) VALUES (2, ‘Partha’, 6.8); INSERT INTO Student (StudentID, FirstName, CGPA) VALUES (3, ‘Gurpreet’, 9.5); INSERT INTO Student (StudentID, FirstName, CGPA) VALUES (4, ‘Neharika’, 7.2); Nahida Nazir
  • 38. SELECT STATEMENT The SELECT statement is used to select data from a database. For retrieving all the columns and rows: Syntax SELECT * FROM table_name; Example Ques: Show the records of all the students from ‘Student’ table. Ans. SELECT * FROM Student; Nahida Nazir
  • 39.  create table ki(id int, roll_no int, salary float, address varchar(20));  insert into ki values(21, 56,67.89, 'hj');  select*from ki;  alter table ki add email varchar(23); ALTER TABLE ki DROP COLUMN Email;  update ki set email='nahida@12.gmail.com’ Nahida Nazir
  • 40. create table ki(id int, roll_no int, salary float, address varchar(20)); insert into ki values(21, 56,67.89, 'hj'); select*from ki; alter table ki add try varchar(23); ALTER TABLE Customers DROP COLUMN Email; update ki set try='89' where id=21; Nahida Nazir
  • 41. SELECT STATEMENT For retrieving specific columns: Syntax SELECT column_name1, column_name2 FROM table_name; Example Ques: Show the columns StudentID, LastName and City from ‘Student’ table. Ans. SELECT StudentID, LastName, City FROM Student; Nahida Nazir
  • 42. SELECT STATEMENT For retrieving records using condition: Syntax SELECT * FROM table_name WHERE condition; Example Ques: Show record of student having StudentID=2 from ‘Student’ table. Ans. SELECT * FROM Student WHERE StudentID=2; Nahida Nazir
  • 43. UPDATING A TABLE The SQL UPDATE Query is used to modify the existing records in a table. You can use WHERE clause with UPDATE query to update selected rows otherwise all the rows would be affected. Syntax UPDATE table_name SET column1=value1, column2=value2,... WHERE some_column=some_value; Nahida Nazir
  • 44. UPDATING A TABLE Example Ques: Update Lastname of student having StudentID=4 . Ans. UPDATE Student SET LastName = ‘Verma’ WHERE StudentID = 4; Ques: Update Address of all the students. Ans. UPDATE Student SET Address = ‘Jal’; Ques: Update CGPA of student having StudentID=3. Ans. UPDATE Student SET CGPA = 9.7 WHERE StudentID = 3; Nahida Nazir
  • 48. ALTERING A TABLE The ALTER TABLE statement is used to add, delete, or modify columns in an existing table. Syntax To add a column: ALTER TABLE table_name ADD column_name datatype; To delete a column: ALTER TABLE table_name DROP COLUMN column_name; Nahida Nazir
  • 50. DELETING FROM TABLE The SQL DELETE Query is used to delete the existing records from a table. You can use WHERE clause with DELETE query to delete selected rows, otherwise all the records would be deleted. Syntax DELETE FROM table_name WHERE some_column=some_value; Nahida Nazir
  • 51. DELETING FROM TABLE Example Ques: Delete the record of student having StudentID=2. Ans. DELETE FROM Student WHERE StudentID=2; Ques: Delete the records of all students living in ‘Jalandhar’. Ans. DELETE FROM Student WHERE Address=‘Jal’; Ques: Delete the records of all the students. Ans. DELETE FROM Student; Nahida Nazir
  • 52. ALTERING A TABLE Example Ques: Add a column FathersName into ‘Student’ table. Ans. ALTER TABLE Student ADD FathersName varchar(30); Ques: Delete column Address from ‘Student’ table. Ans. ALTER TABLE Student DROP COLUMN Address; Nahida Nazir
  • 54. Inserting data into created columns Nahida Nazir
  • 55. RENAMING A COLUMN Syntax rename ki to ui; ALTER TABLE table_name RENAME COLUMN column1 TO column2; Example Ques: Change name of the column StudentID to ID. Ans. ALTER TABLE Student RENAME COLUMN StudentID TO ID; Nahida Nazir
  • 56. DROP TABLE The SQL DROP TABLE statement is used to remove a table definition and all data, triggers, constraints, and permission specifications for that table. NOTE: You have to be careful while using this command because once a table is deleted then all the information available in the table would also be lost forever. Nahida Nazir
  • 57. DROP TABLE Syntax DROP TABLE table_name; Example Ques: Drop the ‘Student’ table. Ans. DROP TABLE Student; Nahida Nazir
  • 58. Delete syntax  delete from ui where id=21; Nahida Nazir
  • 59. TRUNCATE TABLE The SQL TRUNCATE TABLE command is used to delete complete data from an existing table. You can also use DROP TABLE command to delete complete table but it would remove complete table structure form the database and you would need to re-create this table once again if you wish you store some data. Nahida Nazir
  • 60. TRUNCATE TABLE Syntax TRUNCATE TABLE table_name; Example Ques: Truncate the ‘Student’ table. Ans. TRUNCATE TABLE Student; Nahida Nazir
  • 61. Difference among DELETE, DROP, and TRUNCATE DELETE: The DELETE command is used to remove rows from a table. A WHERE clause can be used to only remove some rows. If no WHERE condition is specified, all rows will be removed. After performing a DELETE operation you need to COMMIT or ROLLBACK the transaction to make the change permanent or to undo it. Note that this operation will cause all DELETE triggers on the table to fire. Nahida Nazir
  • 62. Difference among DELETE, DROP, and TRUNCATE TRUNCATE: TRUNCATE removes all rows from a table. The operation cannot be rolled back and no triggers will be fired. As such, TRUNCATE is faster. DROP: The DROP command removes a table from the database. All the tables' rows, indexes and privileges will also be removed. No DML triggers will be fired. The operation cannot be rolled back. Nahida Nazir