2. Storing Data in a Table
• The data that you can add in a table is a row.
• INSERT Statement is used to add row in a
table.
INSERT INTO tablename [column_list)]
VALUES ( {value_list | select_statement})
3. • Inserting New Data
• Inserting Partial Data
• Copying Data from Existing Table
• Inserting Data Interactively
– substitution operator (&) is used for reading data
from keyboard.
4. Guidelines for Inserting Rows
• The number of data values must be same as the
number of columns in the table or column list.
• The order of inserting the information must be
same as the order in which columns are listed in
table or column list
• The data type of information must match with
the data types of the column.
5. Storing Data Using Subqueries
INSERT INTO table_name [ (column1 [, column2 ]) ]
SELECT [ *|column1 [, column2 ]
FROM table1
[ WHERE search_condition];
6. UPDATING Data in a Table
• UPDATE statement is use to make changes in
an existing row(s).
• We can update one or more than one column
of a row.
UPDATE table_name
SET column_name=value [, column_name=value, ...]
[WHERE condition]
7. Guidelines for Updating Rows
• An update can be done only one table at a
time.
• If an update violates integrity constraints,
entire update is rollback.
• If WHERE clause is not used, all rows of a table
will be changed to new values.
8. Updating Data using Subqueries
UPDATE table_name
SET column_name = { new_value |
[(SELECT [*|column1[,column2
] FROM table_name) ]
[WHERE condition]
9. Deleting Data from a Table
• DELETE statement is used to delete row(s)
from a table.
DELETE FROM table_name
[WHERE search_condition]
• TRUNCATE statement can also be used to
delete row(s) from a table.
TRUNCATE TABLE table_name
10. DELETE vs TRUNCATE
• DELETE is a DML statement whereas
TRUNCATE is DDL statement.
• DELETE used to remove rows and WHERE
clause is used to remove some rows whereas
TRUNCATE command delete all rows
• DELETE operations can be rolled back whereas
TRUCATE operation cannot be rolled back.
11. DELETE vs TRUNCATE
• DELETE will fire trigger whereas No triggers
will be fired with TRUNCATE command.
• DELETE does not free the space containing the
table whereas TRUNCATE free space
containing table and can be used by another
table.
12. Delete Data using Subqueries
DELETE FROM table_name
[WHERE column_name operator
[(SELECT column_name FROM table_name [ WHERE
condition])