Hari Dbms
Hari Dbms
1
Ex.no: 1 DDL and DML Commands
Sub. Date: 01/08/2024
Aim:
The aim of this lab assessment is to showcase the use and functionality of various SQL
commands, both Data Definition Language (DDL) and Data Manipulation Language
(DML). The commands covered include CREATE TABLE, INSERT, UPDATE, DELETE,
DROP TABLE, TRUNCATE TABLE, RENAME, and SELECT. Through practical
examples, this lab will demonstrate the processes of creating, modifying, and managing
database tables and their data.Description:
A) DDL
Purpose of command: To create a new table in a database. This command defines the table's
structure by specifying the columns, their data types, and any constraints (such as primary keys,
foreign keys, or unique constraints) that should be applied to the columns.
General syntax:
...
);
Table view before executing a query: Before executing the CREATE TABLE query, there is no
table with the specified name in the database.
Purpose of command: It will destroy the table and all data which will be recorded in it.
General syntax:
Purpose of command: The TRUNCATE TABLE command is used to remove all rows from a
table, effectively deleting all data in the table. However, unlike the DROP TABLE command,
TRUNCATE TABLE does not remove the table structure itself.
General syntax:
Purpose of command: The RENAME command is used to rename an existing table or other
database objects (such as indexes or views) in the database. This command changes the name of
the object without altering its structure or data.
General syntax:
Purpose of command: By the use of ALTER TABLE command, we can modify our existing
table.
General syntax:
Purpose of command: The SELECT command is used to retrieve data from a database. It allows
you to specify which columns of data you want to retrieve, filter rows based on conditions, sort
the data, and perform various other operations.
General syntax:
Before executing the SELECT query, the table exists in the database with its data.
Purpose of command: The INSERT command is used to add new rows of data to a table. It
allows you to specify the values for each column in the new row.
General syntax:
General syntax:
WHERE condition;
Purpose of command: The UPDATE command is used to modify existing records in a table. It
allows you to change the values of one or more columns for all rows that meet a specified
condition.
General syntax:
UPDATE table_name
WHERE condition;
Aim: To understand and demonstrate the functionality of various Data Control Language
(DCL) and Transaction Control Language (TCL) commands in SQL, including GRANT,
REVOKE, COMMIT, ROLLBACK, and SAVEPOINT. These commands are used to
manage user permissions and control transactions within a database, ensuring data
security, integrity, and consistency.
Description:
A) DCL
Purpose of command: The GRANT command is used to provide specific privileges to users
or roles on database objects such as tables, views, and procedures. These privileges
determine what actions the users or roles can perform on the database objects.
General syntax:
ON <object_name>
TO <User_Name>
Purpose of command: Privileges once given can be denied to a user using the REVOKE
command. The object owner can revoke privileges granted to another user. A user of an
object who is not the owner, but has been granted the GRANT privileges, has the power to
REVOKE the privileges from the grantee.
General syntax:
REVOKE <Object_Privileges>
ON <Object_Name>
FROM <User_Name>
B) TCL
Purpose of command: A COMMIT ends the current transaction and makes permanent any
changes made during the transaction. All transaction locks acquired on tables are released.
General syntax:
COMMIT;
Purpose of command: A ROLLBACK does exactly the opposite of COMMIT. It ends the
transaction but undoes any changes made during the transaction. All transaction locks
acquired on tables are released.
General syntax:
1. ROLLBACK;
Purpose of command: SAVEPOINT marks and saves the current point in the processing of
a transaction. When a SAVEPOINT is used with a ROLLBACK statement, parts of a
transaction can be undone. An active save point is one that is specified since the last
COMMIT or ROLLBACK.
General syntax:
SAVEPOINT <SavePointName>
GRANT Command:
REVOKE Command:
COMMIT Command:
• We inserted a new record into the StudentDetails table and then committed the
transaction.
ROLLBACK Command:
• We inserted a new record into the StudentDetails table and then rolled back the
transaction.
SAVEPOINT Command:
• We inserted a new record into the StudentDetails table, created a savepoint, inserted
another record, and then rolled back to the savepoint.