sql-dml(data manipulation language

)
objectives :
*list the types of dml commands *state & demonstrate the use of insert command *state & demonstrate the use of update command *state & demonstrate the use of delete command

sql-dml

*commands

used to manipulate the data in the

database
*data manipulation commands *inserting data into the database tables *modifying data in the database tables *deleting data from the database tables

dml - insert

*inserting data / values into a table : *all rows in a table are inserted using the insert command *syntax : insert into <table name> [(col1, col2, ….)] values (<list of values>); *values for all the columns or selected columns can be

inserted *if column names are omitted the values should be in exactly same order *columns that exists in the table but that are not listed in the insert default to null *character & date data is enclosed within single quotes *null values are given as null
*example : *inserting all values insert into emp values (7315, `john’, `clerk’, 7801, `10-jun-97’, 2500, null, 30); *inserting only some values

insert into emp (empno, ename,sal) values (8234, `samuel’, 6000);

dml - insert
*values

can also be given through a query, if so columns of table must be match the column output of the query *values can also be substituted using parameter substitution *also used to copy rows or partial rows from one table to another table *values clause is replaced by query using select clause
*syntax: insert into <table name> [(col1, col2, ….)] select statement; *example

:
incr table

1. insert the records of all manager’s into with an increment of 300.

dml-insert
*parameter

substitution provides an easier way to enter data into a table *the `&’ symbol is used as the substitution operator *when a substitution operator is used sql*plus prompts for the value of the variable
*examples : *insert a row into emp table using parameters

substitution. insert into emp values (&empno, ‘&ename’, ‘&job’, &mgr, ‘&hiredate’, &salary, null, &deptno);

dml - update
*update

table *values of a single column or a group of columns can be updated *updating can be carried out for all the rows in a table or selected rows (using where clause)
*syntax : update <table_name> set <col_name> = <value> [where <condition>]; *subqueries can also be used with the update command

command is used to modify column values in

dml - update
examples :
1. increase salary of all the employees by 15%. 2. change the department of king to 40. 3. all employees who have more than 2 people reporting to them, are to directly report to president (7839).

dml - delete
*rows

can be deleted using delete statement *the entire row is deleted from the table *set of rows can also be deleted from a table by specifying the condition(s)

dml - delete
*syntax

:

delete [from] <table_name> [where<condition>];
*if

where clause is not specified all the rows will be deleted :

*examples

1. delete all the details of `miller’. 2. delete the records of clerks. 3. delete the records of employees who have not got increment.

transaction processing in oracle
objectives :
*identify the need of transactions *explain what is a transaction *list & explain transaction processing commands

transaction processing
logical unit

*what are transactions? *transaction is a series of operations treated as a single

*why do we need transactions? *with transactions database is never in a state where only

some updates have taken place
*acid properties for transaction *atomicity - a transaction either happens completely, or

none of it happens *consistency - a transaction takes database from one consistent state to the next

transaction processing

*acid properties for transaction *isolation - the effect of transaction is not visible to other

transaction until the transaction is complete *durability - once the transaction is complete, it is permanent

transaction processing
*transaction categories *ddl transactions *implicit *dml transactions *explicit

:

transaction processing in oracle
*a

transaction begins when

*a user logs in into oracle and executes a first ddl or dml

*a

command or *a user executes first ddl or dml command after previous transaction

transaction ends when

*a commit or a rollback is given by the user *a user logs out of oracle *an oracle error occurs *a ddl command is issued

transaction commands
*commit *rollback

commit
*commit

command makes changes permanent to the database :
commit [work];

*syntax

*as

a result of commit *the changes are made permanent to the database *the current transaction is ended *any locks acquired are released *until a transaction is committed, the changes are not visible to other users *a new transaction is started *all ddl transactions implicitly trigger commit

rollback
*changes

made in the transactions can be undone *the complete transaction is undone *rollback restores data to the pre-transaction state
*syntax

:

rollback [work];

rollback

*as a result of rollback *the current transaction is ended *a new transaction is started *any locks acquired are released *in case of system failure, the transaction is undone

(implicit rollback)

partial transactions: savepoint
*transactions

can be divided in to smaller portions using save points *savepoint is a kind of bookmark
*syntax

:

savepoint <save_point_name>;
*you

can undo the changes up to a certain save point using the rollback command :
rollback [work] to save_point_name;

*syntax

partial transactions: savepoint

*the result is *changes made by the statements after that savepoint are

undone *the current savepoint is still active *the savepoints after the current savepoint are deleted *locks acquired after current savepoint are released *transaction is still active

confirming privileges granted

data dictionary view user_tab_privs_made user_tab_privs_recd user_col_privs_made user_col_privs_recd

description object privileges granted on the users objects object privileges granted to the user object privileges granted on the columns of the users objects object privileges granted to the user on specific columns

Sign up to vote on this title
UsefulNot useful