Sunteți pe pagina 1din 10

AMITY SCHOOL OF ENGINEERING AND

TECHNOLOGY

Database Management System


LAB FILE

Submitted By:
Abhinav Dhiman
A2305209103
3CS2, Roll No. 2103

Amity University, Noida

Data Definition Language


The Data Definition Language (DDL) is used to create and destroy
databases and database objects. These commands will primarily be used by
database administrators during the setup and removal phases of a database
project. Let's take a look at the structure and usage of four basic DDL
commands: 

Structure and Usage of some common DDL commands is:


1. CREATE TABLE
This DDL command is used to create a new table into any existing
database.
The syntax of this command is as follows:
Create table <table name> (column_name datatype size constraints,
column_name datatype size constraints, column_name datatype size
constraints,…….);
2. ALTER TABLE

This DDL command is used to add / modify a column in any


existing table of a database.
The syntax of this command is as follows:
Alter table <table name> ADD/MODIFY (column_name datatype
size constraints, column_name datatype size constraints,
column_name datatype size constraints,……);
3. DROP TABLE
This DDL command is used to remove a table from any existing
database.
The syntax of this command is as follows:
Drop table < table name>
DDL Commands Examples

1. CREATE TABLE customer (first_name char(50), last_name


char(50), address char(50),city char(50), country char(50), birth_date
date);
2. CREATE TABLE employee (fname varchar(15), lname varchar(15),
ssn char(9), empid number, salary number);

3. CREATE TABLE department (dname varchar(15), dnumber


number, mgr_ssn char(9), mgr_start_date date);

4. CREATE TABLE dept_locations (dnumber number, dlocation


varchar(15));

5. CREATE TABLE project (pname varchar(15), pnumber number,


plocation varchar(15), dnum number);

6. CREATE TABLE works_on (essn char(9), pno number, hours


number);

7. CREATE TABLE dependent (essn char(9), dependent_name


varchar(15), sex char, birth_date date, relationship varchar(9));

8. ALTER TABLE employee ADD experience number(3);

9. ALTER TABLE employee DROP location;

10. ALTER TABLE employee MODIFY salary number(15,2);

11. ALTER TABLE Person ADD City varchar(30);

12. ALTER TABLE Person DROP COLUMN Address;

13. ALTER TABLE orders ADD discount varchar(10);

14. DROP TABLE employee;

15. DROP TABLE dependent;


Data Manipulation Language

The Data Manipulation Language (DML) is used to retrieve, insert and


modify database information. These commands will be used by all
database users during the routine operation of the database.
Structure and usage of some DML commands are as follows:
1. INSERT

The INSERT command in SQL is used to add records to an existing


table.
The syntax of this command is as follows:
INSERT into <table name> values (value1, value2,
value3, ................., value N );
2. SELECT

This DML command is used to retrieve information from any table


(s) to display/ list/ report on the screen, but this command cannot any
how update/ modify any table.

The syntax of this command is as follows:


Select [*/column list] from <table name> [where <condition>]
[order by <column name> [asc /desc ]] [ group by <column name>]

3. UPDATE
Once there's data in the table, we might find that there is a need to
modify the data. To do so, we can use the UPDATE command.
The syntax of this command is as follows:
UPDATE <tablename> SET <column name> = [new value WHERE
[condition];
4. DELETE

This command deletes all the rows from the table that match
the WHERE clause.

The syntax of this command is as follows:


DELETE FROM <table_name> WHERE <condition>
DML Commands Examples

1. INSERT INTO Persons VALUES (4,'Nilsen', 'Johan', 'Bakken',


'Stavanger');

2. INSERT INTO Persons (P_Id, Last_Name, First_Name) VALUES


(5, 'Tjessem', 'Jakob');

3. INSERT INTO Store_Information (store_name, Sales, Date)


VALUES ('Los Angeles', 900, 'Jan-10-1999');

4. INSERT INTO suppliers (supplier_id, supplier_name)


VALUES (24553, 'IBM');

5. SELECT city, state FROM towntable WHERE population >


'100000';

6. Select * from employee;

7. SELECT store_name FROM Store_Information;

8. SELECT name FROM customers WHERE city='Rome';


9. UPDATE citylist SET population = population+1 WHERE name =
'Argos' and state = 'Indiana';

10. UPDATE Persons SET Address='Nissestien 67', City='Sandnes'


WHERE LastName='Tjessem' AND FirstName='Jakob';

11. UPDATE Persons SET Address='Nissestien 67', City='Sandnes';

12. UPDATE Store_Information SET Sales = 500 WHERE


store_name = "Los Angeles" AND Date = "Jan-08-1999";

13. DELETE FROM suppliers WHERE supplier_name = 'IBM';

14. DELETE FROM citylist WHERE name = 'Argos' and state =


'Indiana';

15. DELETE FROM Store_Information WHERE store_name = "Los


Angeles";
Data Control Language

Data Control Language or DCL is a part Structured Query Language


(SQL) used to control the access to data in a database.

Data Control Language primarily includes the following commands:


1. GRANT: To grant users the right to access the database or perform
certain tasks.

The syntax of this command is as follows:

GRANT [all/specific permissions] ON [tablename] TO [user


account];
2. REVOKE: To cancel any previously granted or denied permission.

The syntax of this command is as follows:

REVOKE [all/specific permissions] ON [tablename] FROM [user


account];

DCL Commands Examples


1. GRANT CREATE TABLE TO user1;

2. REVOKE CREATE TABLE FROM user1;

3. GRANT SELECT ON TABLE MyTable TO user1;

4. REVOKE SELECT ON TABLE MyTable FROM user1;

5. GRANT SELECT ON s,sp TO PUBLIC;

S-ar putea să vă placă și