Professional Documents
Culture Documents
SQL CONCEPTS
Basics of SQL,
DDL,DML,DCL,
Structure creation, alteration,
Defining constraints Primary key, foreign key, unique,
not null, check, IN operator,
Functions - aggregate functions,
Built-in functions numeric, date, string functions,
Set operations
Sub-queries, correlated sub-queries,
Use of group by, having, order by, join and its types, Exist,
Any, All , view and its types.
Transaction Control commands Commit,
BE.COMP - 3rd SEM - DBMS- SQL Concepts - By Prof. Akanksha A. Mishra
Savepoint
Rollback,
INTRODUCTION
When a user wants to get some information from a
database file, he can issue a Query.
A query is a userrequest to retrieve data or information
with a certain condition.
SQL is a query language that allows user to specify
the conditions. (instead of algorithms).
The user specifies certain condition.
The program will go through all the records in the
database file and select those records that satisfy the
condition.(searching).
Statistical information of the data.
The result of the query will then be stored in form of a
table.
BE.COMP - 3rd SEM - DBMS- SQL Concepts - By Prof. Akanksha A. Mishra
INTRODUCTION TO
QUERY
LANGUAGE
Language
:- A language
in which a user
Query
requests
information from the database. These languages are higher
level than that of a standard programming language. Query
Language are classified as :Procedural
Non-Procedural
Requires a programmer to
specify in detail the steps that
are required to complete a
programming task.
User instructs the system to
perform sequence of operations
to compute desired result.
Typical procedural languages
may have 100 lines of coding
instructions.
Extract
information
by
simply telling the system
what information you need
without telling the system
how to perform the data
retrieval.
No detailed programming
instructions required.
So they are very short.
SQL BASICS
SQL is a non-procedural
Sequel.
ANSI & ISO both adopted SQL as the standard language for
RDBMS.
INSERT,SELECT, DELETE,UPDATE
DCL - Data Control Language
GRANT,REVOKE
BE.COMP - 3rd SEM - DBMS- SQL Concepts - By Prof. Akanksha A. Mishra
CONTD
DDL
DML
Data Definition
Language
Data Manipulation
Language
TRUNCATE Removes
DCL
Data Control
Language
GRANT
gives
privilege to the user
REVOKE takes back
privilege granted to
user.
INTRODUCTION TO ORACLE
Security mechanisms
Space Management
Open Connectivity
Oracle versions
ORACLE SQL*PLUS
Table
Name
TABLES IN SQL
Attribut
e Name
Enroll_No
Fname
Lname
DOB
E001
Riya
Patel
12-04-1996
E002
Rohan
Mehta
02-07-1996
E003
Sagar
Shah
24-10-1996
E004
Sima
Mistry
04-11-1996
Students
Tuple
Name
DATA TYPES
Char:-
CONTD
Date:-
Number (P,S):-
CONTD
Long:-
Raw/Long Raw:-
DDL:- CREATE
The CREATE
TABLE statement is used to create a table
COMMAND
in a database.
General Form:-
CREATE
CREATE TABLE
TABLE
Tablename
Tablename
(column_name1
(column_name1
data_type(size),
data_type(size),
column_name2
column_name2
data_type(size),
data_type(size),
xample:- Insert a new
student to the database:
column_name3
column_name3
CREATE
(EnrollNo
varchar(5),
Fname
CREATE TABLE
TABLE Students
Students
(EnrollNo
varchar(5),
Fname
data_type(size),
data_type(size),
varchar(10),
varchar(10),
varchar(10), Lname
Lname....)
varchar(10), DOB
DOB date);
date);
....)
BE.COMP - 3rd SEM - DBMS- SQL Concepts - By Prof. Akanksha A. Mishra
CONTD
INSERT
INSERT INTO
INTO Tablename
Tablename (A1,.,
(A1,., An)
An) VALUES
VALUES (v1,.,
(v1,., vn
vn
OR
INSERT
INSERT INTO
INTO Tablename
Tablename VALUES
VALUES (v1,
(v1,
.,
., vn)
vn)
xample:- Insert a new student to the database:
INSERT
INSERT INTO
INTO Students
Students VALUES
VALUES (E005,
(E005, Shreya,
Shreya,
Shah,28-05-1996)
Shah,28-05-1996)
BE.COMP - 3rd SEM - DBMS- SQL Concepts - By Prof. Akanksha A. Mishra
ALTER TO DROP_COLUMN
ALTER TABLE table_name DROP column column_name;
ALTER TO MODIFY_COLUMN
ALTER TABLE table_name MODIFY column_name
datatype;
ALTER TO RENAME_COLUMN
DML :- UPDATE
The SQL UPDATE
Query is used to modify the existing records in a table.
COMMAND
We can use WHERE clause with UPDATE query to update selected
rows otherwise all the rows would be affected.
UPDATE table_name
SET column1 = value1, column2 = value2....,
columnN = valueN
WHERE [condition];
We can combine N number of conditions using AND/OR operators.
BE.COMP - 3rd SEM - DBMS- SQL Concepts - By Prof. Akanksha A. Mishra
EXAMPLE:
Consider the CUSTOMERS table having the following
records:
DML:- DELETE
COMMAND
The SQL DELETE Query is used to delete the existing records
from a table.
You can use WHERE clause with DELETE query to delete
selected rows, otherwise all the records would be
deleted.
Syntax: The basic syntax of DELETE query with WHERE clause is :
QUERY
DROP TABLE
The SQL DROP TABLE statement is used to remove a
table definition and all data, indexes, triggers, constraints,
and permission specifications for that table.
NOTE: Be careful while using this command because
once a table is deleted then all the information
available in the table would also be lost forever.
ORDER BY COMMAND
WHERE CLAUSE
The SQL WHERE clause is used to specify a condition while fetching
the data from single table or joining with multiple tables.
If the given condition is satisfied then only it returns specific value
from table. WHERE clause to filter the records and fetching only
necessary records.
The WHERE clause is not only used in SELECT statement, but it is
also used in UPDATE, DELETE statement, etc.,
AND OPERATOR
The SQL AND and OR operators are used to combine
multiple conditions to narrow data in an SQL
statement. These two operators are called
conjunctive operators.
These operators provide a means to make multiple
comparisons with different operators in the same SQL
statement.
AND Operator: allows the existence of multiple
conditions in an
SQL statement's WHERE clause.
Syntax:
OR OPERATOR
The OR operator is used to combine multiple conditions in
an SQL statement's WHERE clause.
Syntax:
SELECT column1, column2, columnN FROM table_name
WHERE [condition1] OR [condition2]...OR [conditionN]