SlideShare a Scribd company logo
3
Most read
4
Most read
5
Most read
Database System Sunita M. Dol
Page 1
HANDOUT#02
Aim:
Implementation of SQL DML commands: Insert, Update, and Delete
Theory:
The SQL(Structured Query Language) Language has several parts:
1. Data-definition language (DDL). The SQL DDL provides commands for defining
relation schemas, deleting relations, and modifying relation schemas.
2. Interactive data-manipulation language (DML). The SQL DML includes a query
language based on both the relational algebra and the tuple relational calculus. It
includes also commands to insert tuples into, delete tuples from, and modify tuples in
the database.
3. View definition. The SQL DDL includes commands for defining views.
4. Transaction control. SQL includes commands for specifying the beginning and
ending of transactions.
5. Embedded SQL and dynamic SQL. Embedded and dynamic SQL define how SQL
statements can be embedded within general-purpose programming languages, such as
C, C++, Java, PL/I, Cobol, Pascal, and Fortran.
6. Integrity. The SQL DDL includes commands for specifying integrity constraints that
the data stored in the database must satisfy. Updates that violate integrity constraints
are disallowed.
7. Authorization. The SQL DDL includes commands for specifying access rights to
relations and views.
Domain Types in SQL:
char(n). Fixed length character string, with user-specified length n.
varchar(n). Variable length character strings, with user-specified maximum length
n.
int. Integer (a finite subset of the integers that is machine-dependent).
smallint. Small integer (a machine-dependent subset of the integer domain type).
numeric(p,d). Fixed point number, with user-specified precision of p digits, with n
digits to the right of decimal point.
real, double precision. Floating point and double-precision floating point numbers,
with machine-dependent precision.
float(n). Floating point number, with user-specified precision of at least n digits.
Database System Sunita M. Dol
Page 2
DML
The SQL DML includes a query language based on both the relational algebra and the tuple
relational calculus. It includes also commands to
insert tuples into,
delete tuples from, and
modify tuples in the database.
INSERT Command
It is possible to write the INSERT INTO statement in two ways.
• Method 1: The first way specifies both the column names and the values to be
inserted:
INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);
• Method 2: If you are adding values for all the columns of the table, you do not
need to specify the column names in the SQL query. However, make sure the
order of the values is in the same order as the columns in the table. The INSERT
INTO syntax would be as follows:
INSERT INTO table_name
VALUES (value1, value2, value3, ...);
You can populate data into a table through select statement over another table provided
another table has a set of fields, which are required to populate first table. Here is the
syntax:
INSERT INTO first_table_name [(column1, column2, ... columnN)]
SELECT column1, column2, ...columnN
FROM second_table_name
[WHERE condition];
Insert multiple rows in relation:
• Method 1:The syntax for the INSERT ALL statement:
INSERT ALL
INTO mytable (column1, column2,... column_n) VALUES (expr1,
expr2,... expr_n)
INTO mytable (column1, column2,... column_n) VALUES (expr1,
expr2,... expr_n)
INTO mytable (column1, column2,... column_n) VALUES (expr1,
expr2,... expr_n)
SELECT * FROM dual;
• Method 2: The syntax for the INSERT statement is
INSERT INTO table_name (column1, column2,...columnN.) VALUES
(&column1, &column2, ... &columnN)
If the type of attribute is CHAR or VARCHAR then use single quote in values
e.g. ‘&column1’ else simple use &column1. For inserting remaining rows, simply
used ‘/’.
Database System Sunita M. Dol
Page 3
UPDATE Command
The syntax for the UPDATE statement when updating a table in SQL is:
UPDATE table
SET column1 = expression1,
column2 = expression2,
...
[WHERE conditions];
OR
The syntax for the SQL UPDATE statement when updating a table with data from
another table is:
UPDATE table1
SET column1 = (SELECT expression1
FROM table2
WHERE conditions)
[WHERE conditions];
OR
The syntax for the SQL UPDATE statement when updating multiple tables (not permitted
in Oracle) is:
UPDATE table1, table2, ...
SET column1 = expression1,
column2 = expression2,
...
WHERE table1.column = table2.column
[AND conditions];
DELETE Command
The syntax for the DELETE statement in SQL is:
DELETE FROM table
[WHERE conditions];
Queries and Output:
CREATE Command and Adding Constraints on Relation
SQL> create table branch
2 (branch_name char(15),
3 branch_city char(15),
4 assets numeric(16,2),
5 primary key(branch_name),
6 check(assets>=0));
Table created.
Database System Sunita M. Dol
Page 4
SQL> desc branch;
Name Null? Type
----------------------------------------- -------- ----------------------------
BRANCH_NAME NOT NULL CHAR(15)
BRANCH_CITY CHAR(15)
ASSETS NUMBER(16,2)
INSERT Command
SQL> insert into branch(branch_name,branch_city,assets)
values('&branch_name','&branch_city',&assets
);
Enter value for branch_name: Brighton
Enter value for branch_city: Brooklyn
Enter value for assets: 7100000
old 1: insert into branch(branch_name,branch_city,assets)
values('&branch_name','&branch_city',&assets)
new 1: insert into branch(branch_name,branch_city,assets)
values('Brighton','Brooklyn',7100000)
1 row created.
.
.
SQL> select * from branch;
BRANCH_NAME BRANCH_CITY ASSETS
--------------- --------------- ----------
Brighton Brooklyn 7100000
Downtown Brooklyn 9000000
Mianus Horseneck 400000
North Town Rye 3700000
Perryridge Horseneck 1700000
Pownal Bennington 300000
Redwood Palo Alto 2100000
Round Hill Horseneck 8000000
8 rows selected.
SQL> create table account
2 (account_number char(10),
3 branch_name char(15),
Database System Sunita M. Dol
Page 5
4 balance numeric(12,2),
5 primary key(account_number),
6 foreign key(branch_name)references branch,
7 check(balance>=0));
Table created.
SQL> desc account;
Name Null? Type
----------------------------------------- -------- ----------------------------
ACCOUNT_NUMBER NOT NULL CHAR(10)
BRANCH_NAME CHAR(15)
BALANCE NUMBER(12,2)
SQL> insert into account(account_number,branch_name,balance)
values('&account_number','&branch_name'
,&balance);
Enter value for account_number: A-101
Enter value for branch_name: Downtown
Enter value for balance: 500
old 1: insert into account(account_number,branch_name,balance)
values('&account_number','&branch_name'
,&balance)
new 1: insert into account(account_number,branch_name,balance) values('A-
101','Downtown',500)
1 row created.
.
.
.
SQL> select * from account;
ACCOUNT_NU BRANCH_NAME BALANCE
---------- --------------- ----------
A-101 Downtown 500
A-102 Perryridge 400
A-201 Brighton 900
A-215 Mianus 700
A-217 Brighton 750
A-222 Redwood 700
Database System Sunita M. Dol
Page 6
A-305 Round Hill 350
7 rows selected.
SQL> create table student(roll_no char(10),first_name char(30),middle_name
char(30),last_name char(3
0),address char(50),city char(20),pincode numeric(6,0),state char(20),mobile_number integer);
Table created.
UPDATE Command
SQL> select * from student;
ROLL_NO FIRST_NAME MIDDLE_NAME
---------- ------------------------------ ------------------------------
LAST_NAME
------------------------------
ADDRESS CITY
-------------------------------------------------- --------------------
PINCODE STATE MOBILE_NUM
---------- -------------------- ----------
TECSE-16 Namrata M
Bura
Bhadrawati peth Solapur
413005 Maharashtra 9421067511
ROLL_NO FIRST_NAME MIDDLE_NAME
---------- ------------------------------ ------------------------------
LAST_NAME
------------------------------
ADDRESS CITY
-------------------------------------------------- --------------------
PINCODE STATE MOBILE_NUM
---------- -------------------- ----------
TECSE-26 Pradnya N
Dudam
Sakhar Peth Solapur
413005 Maharashtra 7745865343
Database System Sunita M. Dol
Page 7
SQL> update student set middle_name='Minesh' where roll_no='TECSE-16';
1 row updated.
SQL> select * from student;
ROLL_NO FIRST_NAME MIDDLE_NAME
---------- ------------------------------ ------------------------------
LAST_NAME
------------------------------
ADDRESS CITY
-------------------------------------------------- --------------------
PINCODE STATE MOBILE_NUM
---------- -------------------- ----------
TECSE-16 Namrata Minesh
Bura
Bhadrawati peth Solapur
413005 Maharashtra 9421067511
ROLL_NO FIRST_NAME MIDDLE_NAME
---------- ------------------------------ ------------------------------
LAST_NAME
------------------------------
ADDRESS CITY
-------------------------------------------------- --------------------
PINCODE STATE MOBILE_NUM
---------- -------------------- ----------
TECSE-26 Pradnya N
Dudam
Sakhar Peth Solapur
413005 Maharashtra 7745865343
DELETE Command
SQL> delete from student where roll_no='TECSE-26';
1 row deleted.
Database System Sunita M. Dol
Page 8
SQL> select * from student;
ROLL_NO FIRST_NAME MIDDLE_NAME
---------- ------------------------------ ------------------------------
LAST_NAME
------------------------------
ADDRESS CITY
-------------------------------------------------- --------------------
PINCODE STATE MOBILE_NUM
---------- -------------------- ----------
TECSE-16 Namrata Minesh
Bura
Bhadrawati peth Solapur
413005 Maharashtra 9421067511
Conclusion:
We have studied the various DML commands like
a. INSERT command
b. DELETE command
c. UPDATE command
References:
• Database system concepts by Abraham Silberschatz, Henry F. Korth, S. Sudarshan
(McGraw Hill International Edition) sixth edition.
• Database system concepts by Abraham Silberschatz, Henry F. Korth, S. Sudarshan
(McGraw Hill International Edition) fifth edition.
• http://codex.cs.yale.edu/avi/db-book/db4/slide-dir/
• http://codex.cs.yale.edu/avi/db-book/db5/slide-dir/
• http://codex.cs.yale.edu/avi/db-book/db6/slide-dir/

More Related Content

PDF
Assignment#01
Sunita Milind Dol
 
PPT
Data abstraction and object orientation
Hoang Nguyen
 
PPT
Runnable interface.34
myrajendra
 
PPT
plsql.ppt
faizan992426
 
PPTX
Unix architecture | Operating System
Sumit Pandey
 
DOCX
Data Structure Project File
Deyvessh kumar
 
PPT
Sequences and indexes
Balqees Al.Mubarak
 
PPTX
Linked List - Insertion & Deletion
Afaq Mansoor Khan
 
Assignment#01
Sunita Milind Dol
 
Data abstraction and object orientation
Hoang Nguyen
 
Runnable interface.34
myrajendra
 
plsql.ppt
faizan992426
 
Unix architecture | Operating System
Sumit Pandey
 
Data Structure Project File
Deyvessh kumar
 
Sequences and indexes
Balqees Al.Mubarak
 
Linked List - Insertion & Deletion
Afaq Mansoor Khan
 

What's hot (20)

PPT
Cursores explicitos
marvinarevalo83
 
PPTX
Avl trees
amna izzat
 
PDF
java.io - streams and files
Marcello Thiry
 
PDF
Java arrays
Kuppusamy P
 
ODP
Introduction to triggers
Command Prompt., Inc
 
PPT
Introduction to SQL
Dr. Thippeswamy S.
 
PPT
1 - Introduction to PL/SQL
rehaniltifat
 
PPT
Introduction to structured query language (sql)
Sabana Maharjan
 
PPTX
Object oriented database concepts
Temesgenthanks
 
PPTX
Database Triggers
Shaharyar Nawaz
 
PPT
Sql dml & tcl 2
Dr. C.V. Suresh Babu
 
PPSX
Sql triggers
Chandan Banerjee
 
PPTX
Basic SQL and History
SomeshwarMoholkar
 
PPT
SQL : introduction
Shakila Mahjabin
 
PPT
4. Classes and Methods
Nilesh Dalvi
 
PPT
Unit 1 introduction to data structure
kalyanineve
 
PDF
StringTokenizer in java
Muthukumaran Subramanian
 
PDF
Packages - PL/SQL
Esmita Gupta
 
PPTX
SQL Commands
Sachidananda M H
 
PPTX
Static Members-Java.pptx
ADDAGIRIVENKATARAVIC
 
Cursores explicitos
marvinarevalo83
 
Avl trees
amna izzat
 
java.io - streams and files
Marcello Thiry
 
Java arrays
Kuppusamy P
 
Introduction to triggers
Command Prompt., Inc
 
Introduction to SQL
Dr. Thippeswamy S.
 
1 - Introduction to PL/SQL
rehaniltifat
 
Introduction to structured query language (sql)
Sabana Maharjan
 
Object oriented database concepts
Temesgenthanks
 
Database Triggers
Shaharyar Nawaz
 
Sql dml & tcl 2
Dr. C.V. Suresh Babu
 
Sql triggers
Chandan Banerjee
 
Basic SQL and History
SomeshwarMoholkar
 
SQL : introduction
Shakila Mahjabin
 
4. Classes and Methods
Nilesh Dalvi
 
Unit 1 introduction to data structure
kalyanineve
 
StringTokenizer in java
Muthukumaran Subramanian
 
Packages - PL/SQL
Esmita Gupta
 
SQL Commands
Sachidananda M H
 
Static Members-Java.pptx
ADDAGIRIVENKATARAVIC
 
Ad

Similar to Assignment#02 (20)

PPTX
SQL Query
Imam340267
 
DOCX
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
SakkaravarthiS1
 
PPTX
SQL DATABASE MANAGAEMENT SYSTEM FOR CLASS 12 CBSE
sdnsdf
 
PPT
Interactive SQL: SQL, Features of SQL, DDL & DML
IsakkiDeviP
 
PDF
SQL Notes
JitendraYadav351971
 
PDF
SQL-Notes.pdf mba students database note
MrSushilMaurya
 
PPT
Lab_04.ppt opreating system of computer lab
MUHAMMADANSAR76
 
PDF
Sql smart reference_by_prasad
paddu123
 
PDF
Sql smart reference_by_prasad
paddu123
 
PPTX
Sql commands
Pooja Dixit
 
DOCX
SQL Tutorial for BCA-2
Raj vardhan
 
PPTX
SQl data base management and design
franckelsania20
 
PDF
SQL Overview
Stewart Rogers
 
PPTX
SQL - DML and DDL Commands
Shrija Madhu
 
PPTX
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
EliasPetros
 
PDF
Sql overview-1232931296681161-1
sagaroceanic11
 
PDF
CS3481_Database Management Laboratory .pdf
Kirubaburi R
 
PPTX
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
EliasPetros
 
PPTX
DATABASE MANAGMENT SYSTEM (DBMS) AND SQL
Dev Chauhan
 
DOC
Oracle sql material
prathap kumar
 
SQL Query
Imam340267
 
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
SakkaravarthiS1
 
SQL DATABASE MANAGAEMENT SYSTEM FOR CLASS 12 CBSE
sdnsdf
 
Interactive SQL: SQL, Features of SQL, DDL & DML
IsakkiDeviP
 
SQL-Notes.pdf mba students database note
MrSushilMaurya
 
Lab_04.ppt opreating system of computer lab
MUHAMMADANSAR76
 
Sql smart reference_by_prasad
paddu123
 
Sql smart reference_by_prasad
paddu123
 
Sql commands
Pooja Dixit
 
SQL Tutorial for BCA-2
Raj vardhan
 
SQl data base management and design
franckelsania20
 
SQL Overview
Stewart Rogers
 
SQL - DML and DDL Commands
Shrija Madhu
 
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
EliasPetros
 
Sql overview-1232931296681161-1
sagaroceanic11
 
CS3481_Database Management Laboratory .pdf
Kirubaburi R
 
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
EliasPetros
 
DATABASE MANAGMENT SYSTEM (DBMS) AND SQL
Dev Chauhan
 
Oracle sql material
prathap kumar
 
Ad

More from Sunita Milind Dol (20)

PDF
Assignment No. 10 on Unit-IV Set Theory, Relations and Function
Sunita Milind Dol
 
PDF
Assignment No. 9 on Unit-IV Set Theory, Relations and Function
Sunita Milind Dol
 
PDF
Assignment No. 8 on Unit-IV Set Theory, Relations and Function
Sunita Milind Dol
 
PDF
Assignment No. 7 on Unit-IV - Set Theory, Relations and Function
Sunita Milind Dol
 
PDF
Assignment No. 6 on Representation of Expression
Sunita Milind Dol
 
PDF
Assignment No. 5 on Unit-III Representation of Expression
Sunita Milind Dol
 
PDF
Assignment No. 4 on Unit-II Mathematical Logic
Sunita Milind Dol
 
PDF
Assignment No. 3 on Unit-II Mathematical Logic
Sunita Milind Dol
 
PDF
Assignment No. 2 on Unit-I Mathematical Induction
Sunita Milind Dol
 
PDF
Assignment No. 1 on Unit-I Fundamental Principles of Counting
Sunita Milind Dol
 
PDF
Unit Number 5 - Research Ethics, IPR and Publishing
Sunita Milind Dol
 
PDF
Unit Number 4 - Research reports and Thesis writing
Sunita Milind Dol
 
PDF
Unit Number 3 - Data collection and Statistical Analysis
Sunita Milind Dol
 
PDF
Unit Number 2 - Research Problem Formulation and Methods
Sunita Milind Dol
 
PDF
Unit Number 1 - Introduction to Research
Sunita Milind Dol
 
PDF
Unit Number 5 - Research Ethics, IPR and Publishing
Sunita Milind Dol
 
PDF
Unit Number 5 - Research reports and Thesis writing
Sunita Milind Dol
 
PDF
Unit Number 3 - Data collection and Statistical Analysis
Sunita Milind Dol
 
PDF
Unit Number 2 - Research Problem Formulation and Methods
Sunita Milind Dol
 
PDF
Unit Number 1 : Introduction to Research
Sunita Milind Dol
 
Assignment No. 10 on Unit-IV Set Theory, Relations and Function
Sunita Milind Dol
 
Assignment No. 9 on Unit-IV Set Theory, Relations and Function
Sunita Milind Dol
 
Assignment No. 8 on Unit-IV Set Theory, Relations and Function
Sunita Milind Dol
 
Assignment No. 7 on Unit-IV - Set Theory, Relations and Function
Sunita Milind Dol
 
Assignment No. 6 on Representation of Expression
Sunita Milind Dol
 
Assignment No. 5 on Unit-III Representation of Expression
Sunita Milind Dol
 
Assignment No. 4 on Unit-II Mathematical Logic
Sunita Milind Dol
 
Assignment No. 3 on Unit-II Mathematical Logic
Sunita Milind Dol
 
Assignment No. 2 on Unit-I Mathematical Induction
Sunita Milind Dol
 
Assignment No. 1 on Unit-I Fundamental Principles of Counting
Sunita Milind Dol
 
Unit Number 5 - Research Ethics, IPR and Publishing
Sunita Milind Dol
 
Unit Number 4 - Research reports and Thesis writing
Sunita Milind Dol
 
Unit Number 3 - Data collection and Statistical Analysis
Sunita Milind Dol
 
Unit Number 2 - Research Problem Formulation and Methods
Sunita Milind Dol
 
Unit Number 1 - Introduction to Research
Sunita Milind Dol
 
Unit Number 5 - Research Ethics, IPR and Publishing
Sunita Milind Dol
 
Unit Number 5 - Research reports and Thesis writing
Sunita Milind Dol
 
Unit Number 3 - Data collection and Statistical Analysis
Sunita Milind Dol
 
Unit Number 2 - Research Problem Formulation and Methods
Sunita Milind Dol
 
Unit Number 1 : Introduction to Research
Sunita Milind Dol
 

Recently uploaded (20)

PDF
Construction of a Thermal Vacuum Chamber for Environment Test of Triple CubeS...
2208441
 
PDF
Advanced LangChain & RAG: Building a Financial AI Assistant with Real-Time Data
Soufiane Sejjari
 
PPTX
business incubation centre aaaaaaaaaaaaaa
hodeeesite4
 
PDF
LEAP-1B presedntation xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
hatem173148
 
PDF
20ME702-Mechatronics-UNIT-1,UNIT-2,UNIT-3,UNIT-4,UNIT-5, 2025-2026
Mohanumar S
 
PPT
1. SYSTEMS, ROLES, AND DEVELOPMENT METHODOLOGIES.ppt
zilow058
 
PPTX
Civil Engineering Practices_BY Sh.JP Mishra 23.09.pptx
bineetmishra1990
 
PDF
Zero carbon Building Design Guidelines V4
BassemOsman1
 
PPTX
FUNDAMENTALS OF ELECTRIC VEHICLES UNIT-1
MikkiliSuresh
 
PDF
Unit I Part II.pdf : Security Fundamentals
Dr. Madhuri Jawale
 
PPTX
22PCOAM21 Session 2 Understanding Data Source.pptx
Guru Nanak Technical Institutions
 
PDF
AI-Driven IoT-Enabled UAV Inspection Framework for Predictive Maintenance and...
ijcncjournal019
 
PDF
Cryptography and Information :Security Fundamentals
Dr. Madhuri Jawale
 
PDF
All chapters of Strength of materials.ppt
girmabiniyam1234
 
PPTX
Inventory management chapter in automation and robotics.
atisht0104
 
PPTX
Information Retrieval and Extraction - Module 7
premSankar19
 
PDF
Chad Ayach - A Versatile Aerospace Professional
Chad Ayach
 
PDF
FLEX-LNG-Company-Presentation-Nov-2017.pdf
jbloggzs
 
PDF
2025 Laurence Sigler - Advancing Decision Support. Content Management Ecommer...
Francisco Javier Mora Serrano
 
PDF
The Effect of Artifact Removal from EEG Signals on the Detection of Epileptic...
Partho Prosad
 
Construction of a Thermal Vacuum Chamber for Environment Test of Triple CubeS...
2208441
 
Advanced LangChain & RAG: Building a Financial AI Assistant with Real-Time Data
Soufiane Sejjari
 
business incubation centre aaaaaaaaaaaaaa
hodeeesite4
 
LEAP-1B presedntation xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
hatem173148
 
20ME702-Mechatronics-UNIT-1,UNIT-2,UNIT-3,UNIT-4,UNIT-5, 2025-2026
Mohanumar S
 
1. SYSTEMS, ROLES, AND DEVELOPMENT METHODOLOGIES.ppt
zilow058
 
Civil Engineering Practices_BY Sh.JP Mishra 23.09.pptx
bineetmishra1990
 
Zero carbon Building Design Guidelines V4
BassemOsman1
 
FUNDAMENTALS OF ELECTRIC VEHICLES UNIT-1
MikkiliSuresh
 
Unit I Part II.pdf : Security Fundamentals
Dr. Madhuri Jawale
 
22PCOAM21 Session 2 Understanding Data Source.pptx
Guru Nanak Technical Institutions
 
AI-Driven IoT-Enabled UAV Inspection Framework for Predictive Maintenance and...
ijcncjournal019
 
Cryptography and Information :Security Fundamentals
Dr. Madhuri Jawale
 
All chapters of Strength of materials.ppt
girmabiniyam1234
 
Inventory management chapter in automation and robotics.
atisht0104
 
Information Retrieval and Extraction - Module 7
premSankar19
 
Chad Ayach - A Versatile Aerospace Professional
Chad Ayach
 
FLEX-LNG-Company-Presentation-Nov-2017.pdf
jbloggzs
 
2025 Laurence Sigler - Advancing Decision Support. Content Management Ecommer...
Francisco Javier Mora Serrano
 
The Effect of Artifact Removal from EEG Signals on the Detection of Epileptic...
Partho Prosad
 

Assignment#02

  • 1. Database System Sunita M. Dol Page 1 HANDOUT#02 Aim: Implementation of SQL DML commands: Insert, Update, and Delete Theory: The SQL(Structured Query Language) Language has several parts: 1. Data-definition language (DDL). The SQL DDL provides commands for defining relation schemas, deleting relations, and modifying relation schemas. 2. Interactive data-manipulation language (DML). The SQL DML includes a query language based on both the relational algebra and the tuple relational calculus. It includes also commands to insert tuples into, delete tuples from, and modify tuples in the database. 3. View definition. The SQL DDL includes commands for defining views. 4. Transaction control. SQL includes commands for specifying the beginning and ending of transactions. 5. Embedded SQL and dynamic SQL. Embedded and dynamic SQL define how SQL statements can be embedded within general-purpose programming languages, such as C, C++, Java, PL/I, Cobol, Pascal, and Fortran. 6. Integrity. The SQL DDL includes commands for specifying integrity constraints that the data stored in the database must satisfy. Updates that violate integrity constraints are disallowed. 7. Authorization. The SQL DDL includes commands for specifying access rights to relations and views. Domain Types in SQL: char(n). Fixed length character string, with user-specified length n. varchar(n). Variable length character strings, with user-specified maximum length n. int. Integer (a finite subset of the integers that is machine-dependent). smallint. Small integer (a machine-dependent subset of the integer domain type). numeric(p,d). Fixed point number, with user-specified precision of p digits, with n digits to the right of decimal point. real, double precision. Floating point and double-precision floating point numbers, with machine-dependent precision. float(n). Floating point number, with user-specified precision of at least n digits.
  • 2. Database System Sunita M. Dol Page 2 DML The SQL DML includes a query language based on both the relational algebra and the tuple relational calculus. It includes also commands to insert tuples into, delete tuples from, and modify tuples in the database. INSERT Command It is possible to write the INSERT INTO statement in two ways. • Method 1: The first way specifies both the column names and the values to be inserted: INSERT INTO table_name (column1, column2, column3, ...) VALUES (value1, value2, value3, ...); • Method 2: If you are adding values for all the columns of the table, you do not need to specify the column names in the SQL query. However, make sure the order of the values is in the same order as the columns in the table. The INSERT INTO syntax would be as follows: INSERT INTO table_name VALUES (value1, value2, value3, ...); You can populate data into a table through select statement over another table provided another table has a set of fields, which are required to populate first table. Here is the syntax: INSERT INTO first_table_name [(column1, column2, ... columnN)] SELECT column1, column2, ...columnN FROM second_table_name [WHERE condition]; Insert multiple rows in relation: • Method 1:The syntax for the INSERT ALL statement: INSERT ALL INTO mytable (column1, column2,... column_n) VALUES (expr1, expr2,... expr_n) INTO mytable (column1, column2,... column_n) VALUES (expr1, expr2,... expr_n) INTO mytable (column1, column2,... column_n) VALUES (expr1, expr2,... expr_n) SELECT * FROM dual; • Method 2: The syntax for the INSERT statement is INSERT INTO table_name (column1, column2,...columnN.) VALUES (&column1, &column2, ... &columnN) If the type of attribute is CHAR or VARCHAR then use single quote in values e.g. ‘&column1’ else simple use &column1. For inserting remaining rows, simply used ‘/’.
  • 3. Database System Sunita M. Dol Page 3 UPDATE Command The syntax for the UPDATE statement when updating a table in SQL is: UPDATE table SET column1 = expression1, column2 = expression2, ... [WHERE conditions]; OR The syntax for the SQL UPDATE statement when updating a table with data from another table is: UPDATE table1 SET column1 = (SELECT expression1 FROM table2 WHERE conditions) [WHERE conditions]; OR The syntax for the SQL UPDATE statement when updating multiple tables (not permitted in Oracle) is: UPDATE table1, table2, ... SET column1 = expression1, column2 = expression2, ... WHERE table1.column = table2.column [AND conditions]; DELETE Command The syntax for the DELETE statement in SQL is: DELETE FROM table [WHERE conditions]; Queries and Output: CREATE Command and Adding Constraints on Relation SQL> create table branch 2 (branch_name char(15), 3 branch_city char(15), 4 assets numeric(16,2), 5 primary key(branch_name), 6 check(assets>=0)); Table created.
  • 4. Database System Sunita M. Dol Page 4 SQL> desc branch; Name Null? Type ----------------------------------------- -------- ---------------------------- BRANCH_NAME NOT NULL CHAR(15) BRANCH_CITY CHAR(15) ASSETS NUMBER(16,2) INSERT Command SQL> insert into branch(branch_name,branch_city,assets) values('&branch_name','&branch_city',&assets ); Enter value for branch_name: Brighton Enter value for branch_city: Brooklyn Enter value for assets: 7100000 old 1: insert into branch(branch_name,branch_city,assets) values('&branch_name','&branch_city',&assets) new 1: insert into branch(branch_name,branch_city,assets) values('Brighton','Brooklyn',7100000) 1 row created. . . SQL> select * from branch; BRANCH_NAME BRANCH_CITY ASSETS --------------- --------------- ---------- Brighton Brooklyn 7100000 Downtown Brooklyn 9000000 Mianus Horseneck 400000 North Town Rye 3700000 Perryridge Horseneck 1700000 Pownal Bennington 300000 Redwood Palo Alto 2100000 Round Hill Horseneck 8000000 8 rows selected. SQL> create table account 2 (account_number char(10), 3 branch_name char(15),
  • 5. Database System Sunita M. Dol Page 5 4 balance numeric(12,2), 5 primary key(account_number), 6 foreign key(branch_name)references branch, 7 check(balance>=0)); Table created. SQL> desc account; Name Null? Type ----------------------------------------- -------- ---------------------------- ACCOUNT_NUMBER NOT NULL CHAR(10) BRANCH_NAME CHAR(15) BALANCE NUMBER(12,2) SQL> insert into account(account_number,branch_name,balance) values('&account_number','&branch_name' ,&balance); Enter value for account_number: A-101 Enter value for branch_name: Downtown Enter value for balance: 500 old 1: insert into account(account_number,branch_name,balance) values('&account_number','&branch_name' ,&balance) new 1: insert into account(account_number,branch_name,balance) values('A- 101','Downtown',500) 1 row created. . . . SQL> select * from account; ACCOUNT_NU BRANCH_NAME BALANCE ---------- --------------- ---------- A-101 Downtown 500 A-102 Perryridge 400 A-201 Brighton 900 A-215 Mianus 700 A-217 Brighton 750 A-222 Redwood 700
  • 6. Database System Sunita M. Dol Page 6 A-305 Round Hill 350 7 rows selected. SQL> create table student(roll_no char(10),first_name char(30),middle_name char(30),last_name char(3 0),address char(50),city char(20),pincode numeric(6,0),state char(20),mobile_number integer); Table created. UPDATE Command SQL> select * from student; ROLL_NO FIRST_NAME MIDDLE_NAME ---------- ------------------------------ ------------------------------ LAST_NAME ------------------------------ ADDRESS CITY -------------------------------------------------- -------------------- PINCODE STATE MOBILE_NUM ---------- -------------------- ---------- TECSE-16 Namrata M Bura Bhadrawati peth Solapur 413005 Maharashtra 9421067511 ROLL_NO FIRST_NAME MIDDLE_NAME ---------- ------------------------------ ------------------------------ LAST_NAME ------------------------------ ADDRESS CITY -------------------------------------------------- -------------------- PINCODE STATE MOBILE_NUM ---------- -------------------- ---------- TECSE-26 Pradnya N Dudam Sakhar Peth Solapur 413005 Maharashtra 7745865343
  • 7. Database System Sunita M. Dol Page 7 SQL> update student set middle_name='Minesh' where roll_no='TECSE-16'; 1 row updated. SQL> select * from student; ROLL_NO FIRST_NAME MIDDLE_NAME ---------- ------------------------------ ------------------------------ LAST_NAME ------------------------------ ADDRESS CITY -------------------------------------------------- -------------------- PINCODE STATE MOBILE_NUM ---------- -------------------- ---------- TECSE-16 Namrata Minesh Bura Bhadrawati peth Solapur 413005 Maharashtra 9421067511 ROLL_NO FIRST_NAME MIDDLE_NAME ---------- ------------------------------ ------------------------------ LAST_NAME ------------------------------ ADDRESS CITY -------------------------------------------------- -------------------- PINCODE STATE MOBILE_NUM ---------- -------------------- ---------- TECSE-26 Pradnya N Dudam Sakhar Peth Solapur 413005 Maharashtra 7745865343 DELETE Command SQL> delete from student where roll_no='TECSE-26'; 1 row deleted.
  • 8. Database System Sunita M. Dol Page 8 SQL> select * from student; ROLL_NO FIRST_NAME MIDDLE_NAME ---------- ------------------------------ ------------------------------ LAST_NAME ------------------------------ ADDRESS CITY -------------------------------------------------- -------------------- PINCODE STATE MOBILE_NUM ---------- -------------------- ---------- TECSE-16 Namrata Minesh Bura Bhadrawati peth Solapur 413005 Maharashtra 9421067511 Conclusion: We have studied the various DML commands like a. INSERT command b. DELETE command c. UPDATE command References: • Database system concepts by Abraham Silberschatz, Henry F. Korth, S. Sudarshan (McGraw Hill International Edition) sixth edition. • Database system concepts by Abraham Silberschatz, Henry F. Korth, S. Sudarshan (McGraw Hill International Edition) fifth edition. • http://codex.cs.yale.edu/avi/db-book/db4/slide-dir/ • http://codex.cs.yale.edu/avi/db-book/db5/slide-dir/ • http://codex.cs.yale.edu/avi/db-book/db6/slide-dir/