1 4 SQL CONCEPT DDLDMLTCL Command
1 4 SQL CONCEPT DDLDMLTCL Command
Introduction to SQL
Introduction to SQL
Structure Query Language(SQL) is a database query language
used for storing and managing data in Relational DBMS. SQL
was the first commercial language introduced for E.F
Codd's Relational model of database.
All DDL commands are auto-committed. That means it saves all the
changes permanently in the database.
SQL Command
DML: Data Manipulation Language
• DML commands are used for manipulating the data
stored in the table and not the table itself.
The above command will create a database named Test, which will be an
empty schema without any table.
To create tables in this newly created database, we can again use the create
command.
Creating a Table
create command can also be used to create tables. Now when we
create a table, we have to specify the details of the columns of the
tables too. We can specify the names and datatypes of various columns
in the create command itself.
• These are used to manage the changes made to the data in a table by
DML statements. It also allows statements to be grouped together
into logical transactions.
COMMIT command
COMMIT command is used to permanently save any transaction into
the database.
When we use any DML command like INSERT, UPDATE or DELETE, the
changes made by these commands are not permanent, until the
current session is closed, the changes made by these commands can be
rolled back.
Following is commit command's syntax,
ROLLBACK command
• This command restores the database to last commited state. It is also used with
SAVEPOINT command to jump to a savepoint in an ongoing transaction.
• If we have used the UPDATE command to make some changes into the database,
and realise that those changes were not required, then we can use the ROLLBACK
command to rollback those changes, if they were not commited using the
COMMIT command.
• Following is rollback command's syntax,
SAVEPOINT command
• SAVEPOINT command is used to temporarily save a transaction so
that you can rollback to that point whenever required.
• In short, using this command we can name the different states of our
data in any table and then rollback to that state using the ROLLBACK
command whenever required.
Using Savepoint and Rollback
Using Savepoint and Rollback
Lets use some SQL queries on the above table and see the results.
Using Savepoint and Rollback
NOTE: SELECT statement is used to show the data stored in the table.
The resultant table will look like,
Now let's use the ROLLBACK command to roll back the
state of data to the savepoint B.
Now let's again use the ROLLBACK command to roll back the
state of data to the savepoint A