0% found this document useful (0 votes)
7 views18 pages

Hari Dbms

Uploaded by

kgopala117
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views18 pages

Hari Dbms

Uploaded by

kgopala117
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 18

Ass. No.

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

1.Command Name: CREATE TABLE

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:

CREATE TABLE table_name (

column1 datatype constraint,

column2 datatype constraint,

column3 datatype constraint,

...

);

Table view before executing a query: Before executing the CREATE TABLE query, there is no
table with the specified name in the database.

Example SQL query & System Response:

Page No. Reg.No:22BCE3218


Name: Hariram
2. Command Name: DROP TABLE

Purpose of command: It will destroy the table and all data which will be recorded in it.

General syntax:

DROP TABLE table_name;

Table view before executing a query:

Example SQL query & System Response:

Page No. Reg.No:22BCE3218


Name: Hariram
Table view after executing a query:

3. Command Name: TRUNCATE TABLE

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:

TRUNCATE TABLE table_name;

Table view before executing a query:

Example SQL query & System Response:

Table view after executing a query:

Page No. Reg.No:22BCE3218


Name: Hariram
4. Command Name: RENAME

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:

RENAME old_table_name TO new_table_name;

Table view before executing a query:

Example SQL query & System Response:

Table view after executing a query:

Page No. Reg.No:22BCE3218


Name: Hariram
5. Command Name: ALTER TABLE

Purpose of command: By the use of ALTER TABLE command, we can modify our existing
table.

General syntax:

ALTER TABLE table_name

ADD (new_column_name datatype(size), ...);

Table view before executing a query:

Example SQL query & System Response

Table view after executing a query:

Page No. Reg.No:22BCE3218


Name: Hariram
B) DML

1. Command Name: SELECT

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:

SELECT * FROM Table_name;

Table view before executing a query:

Before executing the SELECT query, the table exists in the database with its data.

Example SQL query & System Response:

Example SQL query to select all columns and System Response:

Page No. Reg.No:22BCE3218


Name: Hariram
Example SQL query to select only Name and DOB and System Response:

Example SQL query to select a particular row and System Response:

Example SQL query to eliminate duplicates and System Response:

Page No. Reg.No:22BCE3218


Name: Hariram
2. Command Name: INSERT

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:

INSERT INTO table_name (column1, column2, column3, ...)

VALUES (value1, value2, value3, ...);

Table view before executing a query:

Example SQL query & System Response:

Example SQL query and System Response to create a single row:

3. Command Name: DELETE

Page No. Reg.No:22BCE3218


Name: Hariram
Purpose of command: The DELETE command is used to remove rows from a table based on a
specified condition. If no condition is specified, all rows in the table will be deleted.

General syntax:

DELETE FROM table_name

WHERE condition;

If you want to delete all rows in a table:

DELETE FROM table_name;

Table view before executing a query:

Example SQL query & System Response:

3. Command Name: UPDATE

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

Page No. Reg.No:22BCE3218


Name: Hariram
SET column1 = value1, column2 = value2, ...

WHERE condition;

Table view before executing a query:

Example SQL query & System Response:

Page No. Reg.No:22BCE3218


Name: Hariram
Result: We successfully executed various DDL and DML commands to manage and
manipulate the data within a database. We:

1. Created tables using the CREATE TABLE command.

2. Inserted multiple records into tables using the INSERT command.

3. Updated existing records with the UPDATE command.

4. Deleted specific records using the DELETE command.

5. Removed entire tables with the DROP TABLE command.

6. Truncated tables using the TRUNCATE TABLE command.

7. Renamed tables with the RENAME command.

8. Retrieved data from tables using the SELECT command.

Page No. Reg.No:22BCE3218


Name: Hariram
Ex.no: 2 DCL and TCL Commands

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

1.Command Name: GRANT

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:

GRANT <object privileges>

ON <object_name>

TO <User_Name>

[WITH GRANT OPTION]

Table view before executing a query:

Example SQL query & System Response:

Page No. Reg.No:22BCE3218


Name: Hariram
Table view after executing a query:

2.Command Name: REVOKE

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>

Table view before executing a query:

Example SQL query & System Response:

Page No. Reg.No:22BCE3218


Name: Hariram
Table view after executing a query:

B) TCL

1.Command Name: COMMIT

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;

Table view before executing a query:

Example SQL query & System Response:

Page No. Reg.No:22BCE3218


Name: Hariram
Table view after executing a query:

2.Command Name: ROLLBACK

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;

2. ROLLBACK TO < Save-point_Name>

Table view before executing a query:

Example SQL query & System Response:

Table view after executing a query:

Page No. Reg.No:22BCE3218


Name: Hariram
3.Command Name: SAVEPOINT

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>

Table view before executing a query

Example SQL query & System Response:

Page No. Reg.No:22BCE3218


Name: Hariram
Result: We have effectively demonstrated the use of various Data Control Language (DCL)
and Transaction Control Language (TCL) commands in SQL. The following outcomes
were observed:

GRANT Command:

• We successfully granted specific privileges (SELECT, INSERT, UPDATE) to a user


on the StudentDetails table.

• The GRANT command executed with the response: Grant succeeded.

• The user example_user obtained the specified privileges on the table.

REVOKE Command:

• We successfully revoked previously granted privileges (SELECT, INSERT,


UPDATE) from a user on the StudentDetails table.

• The REVOKE command executed with the response: Revoke succeeded.

• The user example_user lost the specified privileges on the table.

COMMIT Command:

• We inserted a new record into the StudentDetails table and then committed the
transaction.

• The COMMIT command executed with the response: Commit complete.

ROLLBACK Command:

• We inserted a new record into the StudentDetails table and then rolled back the
transaction.

• The ROLLBACK command executed with the response: Rollback complete.

SAVEPOINT Command:

• We inserted a new record into the StudentDetails table, created a savepoint, inserted
another record, and then rolled back to the savepoint.

Page No. Reg.No:22BCE3218


Name: Hariram
• The SAVEPOINT command executed with the response: Savepoint created.

• The ROLLBACK TO command executed with the response: Rollback complete.

Page No. Reg.No:22BCE3218


Name: Hariram

You might also like