0% found this document useful (0 votes)
32 views

DBMS

Uploaded by

Ujjawal Gupta
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)
32 views

DBMS

Uploaded by

Ujjawal Gupta
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/ 15

AIM- Execute the Data Definition Language (DDL)

commands.
1. CREATE Command
2. DROP Command
3. ALTER Command
4. TRUNCATE Command
5. RENAME Command

Syntax For Create Command-


CREATE TABLE table name
(
column_Name1 data_type ( size of the column ) , column_Name2
data_type ( size of the column) , column_Name3 data_type ( size of the
column) ,
...
column_NameN data_type ( size of the column )
);

To create a table name as


Ujjawal ---

CREATE TABLE Ujjawal (


admin_no INT PRIMARY KEY,
name VARCHAR(50),
dept VARCHAR(50),
course VARCHAR(50),
totalmarks INT
);
Syntax For Insert Command-
INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);

To Insert data into above table--


INSERT INTO Ujjawal VALUES
(101, 'Ujjawal Gupta', 'Computer Science', 'BCA', 95),
(102, 'Advait Patel', 'Electrical Engineering', 'B.E', 78),
(103, 'Anaya Gupta', 'Mechanical Engineering', 'B.E', 92),
(104, 'Arjun Singh', 'Civil Engineering', 'B.E', 75),
(105, 'Ishaan Verma', 'Information Technology', 'B.Tech', 88),
(106, 'Kavya Reddy', 'Electronics and Communication',
'B.Tech', 91),
(107, 'Mira Joshi', 'Chemical Engineering', 'B.E', 82),
(108, 'Veer Kapoor', 'Aerospace Engineering', 'B.E', 89);
Syntax For Alter Command-
ALTER TABLE name_of_table ADD column_name column_defi
nition;

Using Alter Command in the ujjawal_phonebook table-


ALTER TABLE Ujjawal_gupta ADD Gender CHAR(1) CHECK
(Gender IN ('M', 'F'));

Syntax for Rename Command-


RENAME TABLE Old_Table_Name TO New_Table_Name;

Using Rename Command-


ALTER TABLE Ujjawal RENAME TO Ujjawal_gupta;

Syntax for Truncate Command-


TRUNCATE TABLE Table_Name;

Using Truncate Command-


TRUNCATE TABLE Ujjawal_gupta;

Syntax for Drop Command-


DROP Database Databse_name;
Using Drop Command-
DROP TABLE Ujjawal_gupta;
AIM-Executing DataManipulation Language(DML)
Commands

Data Manipulation Commands are-

1. INSERT Command
2. SELECT Command
3. UPDATE Command
4. DELETE Command

Syntax for Insert Command-


INSERT INTO TABLE_NAME ( column_Name1 ,
column_Name2 , column_Name3 , .... column_NameN )
VALUES (value_1, value_2, value_3, .... value_N ) ;

Executing Insert Command-


INSERT INTO Ujjawal_gupta (admin_no, Name, Dept, Course,
totalmarks) VALUES (109, 'Saurabh Patel', 'Chemical
Engineering','B.Tech',40);
Syntax for Select Command-
SELECT column_Name_1, column_Name_2, …..,
column_Name_N FROM Name_of_table;

Executing Select Command-


Select admin_no,Name,Dept from Ujjawal_gupta where
tota;marks>80;

Syntax for Update Command-


UPDATE Table_name SET [column_name1= value_1, …..,
column_nameN = value_N] WHERE CONDITION;
Executing Update Command-
UPDATE Ujjawal_gupta SET Course = 'BCA' WHERE
Name =
'Saurabh Patel';

Syntax for Delete Command-


DELETE FROM table_name WHERE condition;

Executing Delete Command-


Delete from Ujjawal_gupta where admin_no=102;
AIM - Execution of Data Control Language(DCL) Command

A Data Control Language is a syntax similar to a


computer programming language used to control access
to data stored in a database (Authorization). In particular,
it is a component of Structured Query Language (SQL).
Commands are-
1. Grant
2. Revoke
Grant Command- This command gives users access
privileges to the database.
Syntax for Grant Command-
GRANT SELECT, UPDATE ON MY_TABLE TO SOME_USER, ANOTHER_
USER;

Executing Grant Command-


grant select on *.* to 'ujjawal_0014'@'localhost';
--Grants ujjawal_0014@localhost to access the databases
on root@localhost
grant insert on ujjawal.Ujjawal_gupta to
'ujjawal_0014'@'localhost';
--Grants ujjawal_0014@localhost to use insert command.
grant update(admin_no) on ujjawal.Ujjawal_gupta to
'ujjawal_0014'@'localhost';
--Grants ujjawal_0014@localhost to use update
command.

Before Grant

After Grant
Updated by Ujjawal_0014@localhost side
Revoke Command- This command withdraws the user’s
access privileges given by using the GRANT command.
eSyntax for Revoke Command-
REVOKE SELECT, UPDATE ON MY_TABLE FROM USER1, USER2;

Executing Revoke Command-


revoke update(admin_no) on ujjawal.Ujjawal_gupta from
'ujjawal_0014'@'localhost';
--Revoke access to update Ujjawal.Ujjawal_gupta where
ujjawal is name of Database and inside Ujjawal there is
a table named as Ujjawal_gupta.
revoke insert on ujjawal.Ujjawal_gupta from
'ujjawal_0014'@'localhost';
--Revoke access to insert data into Ujjawal_gupta table.
Revoked all the GRANTS

Revoking all the previous GRANTS.

Some Other Queries related to DCL Commands-


Select user();  use to get the name of current user.
show grants for 'ujjawal_0014'@'localhost';  use to get the
current grant permissons for the mentioned user i.e
Ujjawal_0014@localhost.
system mysql -u ujjawal_0014 -p  use to switch user where
u is user name and p is password for mentioned user.
create use 'ujjawal_0014'@'localhost' identified by '1234'; 
This will create a user named as ujjwaal_0014 and pss is
1234.
AIM- Execution of Transaction Control Language(TCL)
Command
Transaction Control Language commands are used to
manage transactions in the database. These are used to
manage the changes made by DML-statements. It also
allows statements to be grouped together into logical
transactions.
Transaction Control Commands are-
1.Savepoint
2.Rollback
3.Commit
Savepoint- Savepoint command is used to temporarily
save a transaction so that you can rollback to that
point whenever necessary.
Rollback- This command restores the database to last
committed state.

Commit- Commit command is used to permanently save


any transaction into the database.
Aim: Execution of all Aggregate function.

In database management an aggregate function is a


function where the values of multiple rows are grouped
together as input on certain criteria to form a single value
of more significant meaning.

Various Aggregate Functions:


1) Count()
2) Sum()
3) Avg()
4) Min()
5) Max()

Count: SELECT COUNT(Tot_marks) FROM


Ujjawal_gupta;
SUM: SELECT SUM(Tot_marks) FROM Ujjawal_gupta;

MAX:SELECT MAX(Tot_marks) FROM Ujjawal_gupta;

MIN:SELECT MIN(Tot_marks) FROM Ujjawal_gupta;

AVG:SELECT AVG(Tot_marks) FROM Ujjawal_gupta;

You might also like