You are on page 1of 11

PRACTICAL EXAMINATION

ASSIGNMENT DBMS
NAME: Farwa Mehmood Khan

DEPT: BS Softwre Engineeing(Morning)

YEAR: Second Year (4th Semester)

ROLL NO: 2k19/swe/34

SUBJECT: Database Systems

SUBMITED TO: Mr. Z.A Bhutto

ASSIGNMENT TOPIC: Functions Of

Sublanguages Of SQL

DATE: 15-Jan-2021
Database:
Database, also called electronic database, any collection of data,
or information, that is specially organized for rapid search and retrieval
by a computer. Databases are structured to facilitate the storage,
retrieval, modification, and deletion of data in conjunction with various
data-processing operations. A database management system (DBMS)
extracts information from the database in response to queries.

Database Management System (DBMS):


DBMS software primarily functions as an interface between the end
user and the database, simultaneously managing the data, the
database engine, and the database schema(structure) in order to
facilitate the organization and manipulation of data.

Relational Database Management System


(RDBMS):
Relational databases are made up of a set of tables with data that fits
into a predefined category. Each table has at least one data category in
a column, and each row has a certain data instance for the categories
which are defined in the columns.The Structured Query Language (SQL)
is the standard user and application program interface for a relational
database. 

Structured Query Language (SQL):


SQL stands for Structured Query Language.SQL is a standard language
for accessing and manipulating databases.SQL became a standard of
the American National Standards Institute (ANSI) in 1986, and of the
International Organization for Standardization (ISO) in 1987

SQL statements are used to perform tasks such as update data on a


database, or retrieve data from a database. Some common relational
database management systems that use SQL are: Oracle, Sybase,
Microsoft SQL Server, Access, Ingres, etc.

Different iterations of SQL may utilize different syntax for key


operations, in general, basic commands like select, insert, update and
create are common to all SQL releases. This makes it very easy for
someone with a basic knowledge of SQL to work in many different
environments and perform a wide variety of tasks.

SUBLANGUAGES OF SQL COMMANDS:


These are main types of language statements or commands that are
supprted by SQL.

1. DML – Data Manipulation Language.


2. DDL – Data Definition Language.
3. DRL – Data Retrieval Language.
4. DCL – Data Control Language.
5. TCL – Transactional Control Language.
FUNCTIONS OF SUBLANGUAGES OF SQL:

1. Data Manipulation Language (DML):


o DML is abbreviation of Data Manipulation Language. It is used to
retrieve, modify, add, and delete data in database.The command
of DML is not auto-committed that means it can't permanently
save all the changes in the database. They can be rollback.

Examples:  UPDATE, INSERT and DELETE statements,


1. UPDATE: used for modifying the data in the database.

Syntax:

UPDATE table_name SET column1 = value1, column2 = value2,...


WHERE condition;

table_name: name of the table


column1: name of first , second, third column....
value1: new value for first, second, third column....
condition: condition to select the rows for which the
values of columns needs to be updated.
NOTE: In the above query the SET statement is used to set new values
to the particular column and the WHERE clause is used to select the
rows for which the columns are needed to be updated. If we have not
used the WHERE clause then the columns in all the rows will be
updated. So the WHERE clause is used to choose the particular rows.

2. INSERT: used for adding or inserting new data into database.

Syntax:

1. Only values: First method is to specify only the value of data to


be inserted without the column names.

INSERT INTO table_name VALUES (value1, value2, value3,…);


table_name: name of the table.
value1, value2,.. : value of first column, second column,… for the
new record

2. Column names and values both: In the second method we will


specify both the columns which we want to fill and their
corresponding values as shown below:

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


VALUES ( value1, value2, value3,..);
table_name: name of the table.
column1: name of first column, second column …
value1, value2, value3 : value of first column, second column,…
for the new record

3. DELETE: used for deleting the already existing data from


database.

Syntax:

DELETE FROM table_name WHERE some_condition;


table_name: name of the table
some_condition: condition to choose particular record.
Note: We can delete single as well as multiple records depending
on the condition we provide in WHERE clause. If we omit the
WHERE clause then all of the records will be deleted and the table
will be empty.

2. Data Definition Language (DDL)


DDL is abbreviation of Data Definition Language. It is used to create,
modify and destroy the structure of database objects in database.

Examples: CREATE, ALTER, DROP, TRUNCATE ,RENAME statements,


1. CREATE: used for creating database objects like tables, stored
procedures, functions, etc.

Syntax:
CREATE DATABASE database_name;
database_name: name of the database.
Example Query:
This query will create a new database in SQL and name the
database as my_database.
CREATE DATABASE my_database;

2. ALTER: is used to add, delete/drop or modify columns in the


existing table.

Syntax:

ALTER TABLE table_name ADD (Columnname_1 datatype,


Columnname_2 datatype,

Columnname_n datatype);
QUERY:
 To ADD 2 columns AGE and COURSE to table Student.
ALTER TABLE Student ADD (AGE number(3),COURSE
varchar(40));

3. DROP: used to drop or delete the existing database objects.

Syntax:
DROP object object_name

Examples:
DROP TABLE table_name;
table_name: Name of the table to be deleted.
DROP DATABASE database_name;
database_name: Name of the database to be deleted.

4. TRUNCATE: used to delete all the records from table and to reset


identity of column to initial value.

Syntax:
TRUNCATE TABLE table_name;
table_name: Name of the table to be truncated.

5. RENAME:
Sometimes we may want to rename our table to give it a more
relevant name. For this purpose we can use ALTER TABLE to
rename the name of table.

Syntax:
ALTER TABLE table_name
RENAME TO new_table_name;

3.Data Retrieval Language (DRL):


DRL is used to retrieve information from the database objects. it is
for read only purpose.

Example:

SELECT: used for retrieving data from the database.

Syntax:
SELECT column1,column2 FROM table_name
column1 , column2: names of the fields of the table
table_name: from where we want to fetch.

Queries:
 To fetch the entire table or all the fields in the table:
SELECT * FROM table_name;
 Query to fetch the fields ROLL_NO, NAME, AGE from the table
Student:
SELECT ROLL_NO, NAME, AGE FROM Student;

4. Data Control Language(DCL):


DCL is abbreviation of Data Control Language. It is used to create roles,
permissions, and referential integrity as well it is used to control access
to database by securing it.

Examples: GRANT, REVOKE statements,

1. GRANT: used for creating access permissions for users to


database.
2. REVOKE: used for revoking the already assigned permissions.

5.Transactional Control Language (TCL):


TCL is abbreviation of Transactional Control Language. It is used to
manage different transactions occurring within a database.

Examples: COMMIT, ROLLBACK, SAVEPOINT statements,


1. COMMIT: used for saving the work done in a particular
transaction. For example: “Ctrl + S” in word file.

Syntax: 
 COMMIT;

Queries: 
 DELETE FROM Student WHERE AGE = 20;
COMMIT;

2. ROLLBACK: used for reverting the transaction to the original state


before commit. For example: “Ctrl + Z” in word file.

Syntax: 
 ROLLBACK;

Queries: 
 DELETE FROM Student WHERE AGE = 20;
ROLLBACK;

3. SAVEPOINT: SAVEPOINT command is used to temporarily save a


transaction so that you can rollback to that point whenever
required.

Syntax: 

SAVEPOINT SAVEPOINT_NAME;

In general ROLLBACK is used to undo a group of transactions. 

Syntax for rolling back to Savepoint command: 

ROLLBACK TO SAVEPOINT_NAME;

You might also like