0% found this document useful (0 votes)
10 views22 pages

Class 2

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

Class 2

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

Class 2

unit I
SQL
• Structured Query Language (SQL), as we all know,
is the database language by which we can perform
certain operations on the existing database, and we can
also use this language to create a database.
These SQL commands are mainly categorized into five
categories:
1.DDL – Data Definition Language
2.DQL – Data Query Language
3.DML – Data Manipulation Language
4.DCL – Data Control Language
5.TCL – Transaction Control Language
• Data Definition Language actually consists of the SQL
commands that can be used to define the database
schema. It simply deals with descriptions of the
database schema and is used to create and modify the
structure of database objects in the database.
Command Description Syntax
Create database or its
CREATE TABLE table_name
objects (table, index,
CREATE (column1 data_type, column2
function, views, store
data_type, ...);
procedure, and triggers)
Delete objects from the
DROP DROP TABLE table_name;
database
ALTER TABLE table_name ADD
Alter the structure of the
ALTER COLUMN column_name
database
data_type;
Remove all records from a
table, including all spaces
TRUNCATE TRUNCATE TABLE table_name;
allocated for the records are
removed

Add comments to the data COMMENT 'comment_text' ON


COMMENT
dictionary TABLE table_name;

Rename an object existing in RENAME TABLE old_table_name


RENAME
the database TO new_table_name;
• Data Definition Language (DDL)
Specification notation for defining the database schema
Example:
create table instructor (
ID char(5),
name varchar(20),
dept_name varchar(20),
salary numeric(8,2))
DQL (Data Query Language)

Command Description Syntax

SELECT column1,
It is used to retrieve
column2, ...FROM
SELECT data from the
table_name<br>WHE
database
RE condition;

SELECT CustomerName, City FROM Customers;


DML(Data Manipulation Language)

• The SQL commands that deal with the manipulation of


data present in the database
Command Description Syntax

INSERT INTO table_name


INSERT Insert data into a table (column1, column2, ...)
VALUES (value1, value2, ...);

UPDATE table_name SET


Update existing data within
UPDATE column1 = value1, column2
a table
= value2 WHERE condition;

Delete records from a DELETE FROM table_name


DELETE
database table WHERE condition;

LOCK TABLE table_name IN


LOCK Table control concurrency
lock_mode;
• INSERT INTO table_name (column1, column2,
column3)
VALUES ( value1, value2, value);
INSERT INTO Student (ROLL_NO, NAME, ADDRESS,
PHONE, AGE) VALUES (1, 'Ram', 'Delhi', 'XXXXXXXXXX',
18),
(2, 'Ramesh', 'Gurgaon', 'XXXXXXXXXX', 18),
(3, 'Sujit', 'Rohtak', 'XXXXXXXXXX', 20),
(4, 'Suresh', 'Rohtak', 'XXXXXXXXXX', 18);
• DELETE FROM table_name WHERE condition;
• DELETE FROM Customers WHERE CustomerName
='Alfreds Futterkiste’;
• UPDATE table_name SET column1 = value1, column2 =
value2,…
WHERE condition;
• UPDATE Customers
SET ContactName = 'Alfred Schmidt',
City= 'Frankfurt'
WHERE CustomerID = 1;
DCL (Data Control Language)
• DCL includes commands such as GRANT and REVOKE
which mainly deal with the rights, permissions, and
other controls of the database system.
Command Description Syntax
Assigns new GRANT
privileges to a user privilege_type
account, allowing [(column_list)] ON
GRANT access to specific [object_type]
database objects, object_name TO
actions, or user [WITH GRANT
functions. OPTION];

Removes previously REVOKE [GRANT


granted privileges OPTION FOR]
from a user privilege_type
REVOKE account, taking [(column_list)] ON
away their access [object_type]
to certain database object_name FROM
• GRANT privileges_names ON object TO user;
• GRANT SELECT ON employee TO user1;
This command grants a SELECT permission on employee
table to user1

REVOKE privilege_name
ON object_name
FROM {user_name |PUBLIC |role_name}
REVOKE SELECT ON employee FROM user1;
Privileges and Roles:
Privileges: Privileges defines the access rights provided
to a user on a database object. There are two types of
privileges.
1) System privileges - This allows the user to CREATE,
ALTER, or DROP database objects.
2) Object privileges - This allows the user to EXECUTE,
SELECT, INSERT, UPDATE, or DELETE data from database
objects to which the privileges apply.
DBMS ARCHITECTURE
• 1-Tier Architecture
In this architecture, the database is directly available to
the user. It means the user can directly sit on the DBMS
and uses it.
• 2-Tier Architecture
The 2-Tier architecture is same as basic client-server. In
the two-tier architecture, applications on the client end
can directly communicate with the database at the
server side. For this interaction, API's
like: ODBC, JDBC are used.
• 3-Tier Architecture
• The 3-Tier architecture contains another layer between
the client and server. In this architecture, client can't
directly communicate with the server.
• The application on the client-end interacts with an
application server which further communicates with the
database system.
• Internal Level
• The internal level has an internal schema which
describes the physical storage structure of the
database.
• The internal schema is also known as a physical
schema.
• It uses the physical data model. It is used to define that
how the data will be stored in a block.
• The physical level is used to describe complex low-level
data structures in detail.
Conceptual Level
• The conceptual schema describes the design of a
database at the conceptual level. Conceptual level is
also known as logical level.
• The conceptual schema describes the structure of the
whole database.
• The conceptual level describes what data are to be
stored in the database and also describes what
relationship exists among those data.
• In the conceptual level, internal details such as an
implementation of the data structure are hidden.
• Programmers and database administrators work at this
level.
• External Level
At the external level, a database contains several
schemas that sometimes called as subschema. The
subschema is used to describe the different view of the
database.
An external schema is also known as view schema.
Each view schema describes the database part that a
particular user group is interested and hides the
remaining database from that user group.
The view schema describes the end user interaction with
database systems.

You might also like