CONTENTS
( Learning Outcomes )
Understanding Database and DBMS
Some applications of DBMS
Advantages of DBMS
Disadvantages of DBMS
Different Data Models
Understanding Relational Data Model
Relational Data Terminologies
Referential Integrity Constraints
DATABASE MANAGEMENT SYSTEM (DBMS)
What is a database?
Database is a set of inter-related
and persistent data.
OR
Collection of logically related data along
with its description is termed as database.
What is DBMS ?
A set of application programs used to access,
update and manage the inter-related and persistent data.
COMPUTER BASED RECORD KEEPING SYSTEM
DATABASE APPLICATIONS Examples….
1. STUDENT RECORD KEEPING SYSTEM
2. INVENTORY CONTROL MANAGEMENT
3. PERSONNEL MANAGEMENT SYSTEM
4. FINANCIAL ACCOUNTING SYSTEM
5. BANKING SYSTEM
6. AIRLINE RESERVATION SYSTEM
7. HOSPITAL MANAGEMENT SYSTEM
8. HOTEL MANAGEMENT SYSTEM
Why Database????
ADVANTAGES OF DATABASE
Database systems reduce data redundancy to a large extent.
(redundancy meaning duplication)
Database systems control data inconsistency to a large extent.
Database facilitate sharing of data.
Databases enforce standards laid by organization or company
Centralized databases can ensure data security.
Integrity can be maintained through databases. (Eg. Invalid date)
DISADVANTAGES OF DATABASE
Without good controls a database may be
compromised over security and integrity issues
Database systems may require extra hardware.
Performance overhead may be significant.
System is likely to be complex.
DIFFERENT DATA MODELS
A data model refers to a set of concepts to
describe the structure of a database, and certain
constraints that the database should obey.
(i) Relational data models,
(ii) Network data model,
(iii) Hierarchical data model,
(iv) Object oriented data model.
RELATIONAL DATA MODEL
The relational data model is organized
into tables.These tables are called
relations.
A row in a table represents a
relationship among a set of values.
Since a table is a collection of such
relationships, it is generally referred to
using the mathematical term relation, from
which the relational data model derives its
name.
RELATIONAL MODEL TERMINOLOGY
TERMINOLOGY Definition
A relation is a table storing logically related data;
A data must be atomic in a cell;
RELATION
All rows of this table are distinct;
Ordering of rows and columns is immaterial.
This is a pool of a values from which the actual values
DOMAIN
appearing in a given column are drawn
TUPLE /
A row of a relation is generally referred to a tuple.
RECORD/ ROW
ATTRIBUTE/ A column of a relation is generally referred to as an
FIELD/ COLUMN attribute.
This refers to the no. of attributes in a relation.
DEGREE
This refers to no. of tuples in a relation.
CARDINALITY
RELATION:- Dept
DEGREE
Deptno DName Location ATTRIBUTES
10 IT Mumbai
20 Sales Delhi
TUPLES CARDINALITY
30 Marketing Mumbai
40 Finance Kolkata
DOMAIN of
Candidate Key Location column
for Eg.
Primary Key Mumbai, Bangalore,
Delhi, Chennai,
Alternate Key Kolkata,Jaipur, Bhopal,
Hyderabad
RELATIONAL MODEL TERMINOLOGY CONTD.
TERMINOLOGY Definition
This refers to a set of one or more attributes that can
PRIMARY KEY uniquely identify tuples within the relation.
All attribute combinations inside a relation that can
CANDIDATE KEY serve as primary key are candidate keys as they are
candidate for primary key positions.
A candidate key that is not primary key, is called an
ALTERNATE KEY
alternate key.
A non key attribute, whose values are derived from the
FOREIGN KEY primary key of some other table , is known as foreign
key in its current table.
DEPT ( Primary table / Master table)
Deptno DName Location
10 IT Mumbai
20 Sales Delhi
30 Marketing Mumbai
40 Finance Kolkata
Primary Key of DEPT table
EMP ( Foreign table / Detail table)
Primary Key of EMP table Foreign Key
Empno Ename Job Sal Hiredate Deptno
1001 ABC Clerk 20000 25-10-2006 20
1002 EFG Salesman 25000 12-08-2008 10
1006 XYZ Manager 30000 19-05-2008 30
1003 PQR Analyst 30000 10-07-2007 20
REFERENTIAL INTEGRITY
A referential integrity is a system of rules that DBMS uses to
ensure that relationships between records in related tables are valid
and that users don’t accidentally delete or change related data.
CONDITIONS SET FOR REFERENTIAL INTEGRITY CONSTRAINTS
The matching field from the primary table is a primary key or has unique index.
The related field have same data type.
Both table belong to the same database. Referential integrity cannot be enforced for
linked table from database in other format.
RULES FOR REFERENTIAL INTEGRITY CONSTRAINTS
You can’t enter a value in the foreign key field of the related table that doesn’t exist
in the primary key of the primary table.
You can’t delete a record from a primary table if matching records exist in a related
table.
You can’t change a primary key value in the primary table, if that record has
relatedrecords in the foreign key field.
CONTENTS
( LEARNING OUTCOMES )
STRUCTURED QUERY LANGUAGE
Introducing SQL
Key Features of SQL
About MySQL
Classification of SQL commands
DDL Vs DML commands
Introducing SQL
The Structured Query Language(SQL) is
a language that enables you to create
and operate on relational databases,
which are sets of related information
stored in tables.
SQL is the standard relational
database language.
Key Features of SQL
Client/Server environment Convertibility
Large database and space Very fast with ease of use
management Openness, Industry standard
High Availability , free of cost Manageable Security
Portability Many concurrent database
Compatibility users
CLIENT-SERVER ARCHITECTURE
CLIENT
1.
SERVER
Database
2.
About MySQL www.mysql.org
Freely available open source Relational Database
Management System (RDBMS) which is built on the SQL
language.
MySQL is rich in variety of features which support a
secured environment for storing,maintaining and
accessing data.
Fast,reliable,scalable.
A single table developed using MySQL can contain
thousands of tables and each table can hold thousands
of records. Amazing!!!! Right!!!
Chief Inventor- Michael Widenius (a.k.a.Monty)
MySQL name is after Monty’s daughter “My”.
CLASSIFICATION OF SQL COMMANDS
Processing capabilities of SQL
Data Definition Language (DDL) commands
(CREATE, ALTER, DROP, RENAME,TRUNCATE,COMMENT)
Data Control Language (DCL) commands
(GRANT, REVOKE)
Data Manipulation Language (DML) commands
(INSERT, UPDATE, DELETE, SELECT)
Transaction Control Language (TCL) commands
(COMMIT, ROLLBACK, SAVEPOINT,SET TRANSACTION)
Session Control Language commands
(ALTER SESSION,SET ROLL)
System Control Language commands
SQL commands to learn………
DDL DML
DDL stands for data definition DML stands for Data
language. It is component Manipulation Language is a
language of SQL, that provides special language to manipulate
commands for defining data using a set of procedures.
various database objects.
Eg. Create,Alter,Drop Eg. Insert,Delete,Update,Select
It provides statements to enter,
It provides statements for the
update, delete data and
creation and deletion of tables,
perform complex queries on
indexes, views and adding or
these table.
modifying new field in a table.
Data Dictionary
It is the file that stores data about data i.e. it stores the metadata.
CONTENTS
(LEARNING OUTCOMES)
MySQL basic elements
Literals
Data Types
NULL values
Comments
Points to Remember
Commands,Clauses, Keywords,Arguments
What are constraints?
Understanding DDL and DML commands
MySQL basic Elements
LITERALS
DATA TYPES
NULLS
COMMENTS
LITERALS
• Literals refers to a fixed data value.
• Fixed data value may be of character type or numeric literal.
Eg. , ‘Ajay’, “Thomas”, ‘596’ are all character text literals.
• Character literals can be given in either single quote or double quote.
‘ ’ “ ”
• Numbers that are not enclosed in quotation marks are numeric literals
Eg. 5, 350, 84
CONCEPT OF DATA TYPES
DATA TYPES in MySQL
NUMERIC types STRING / TEXT/ DATE & TIME types
CHARACTER types
Int/ Integer/ Number Char Date
Tinyint Varchar
Year
Smallint Varchar2
Time
Mediumint Blob/ Text
Datetime
Bigint TinyBlob
Timestamp
Float MediumBlob
Double LongBlob
Decimal
Data Type: It is the kind of data which a column of a table holds.
DATA TYPES Description Syntax
NUMERIC
Number(size) / Used to store a numeric value in a field/column. Number(4)
Integer(size)/ It may be decimal, integer or a real value.
Int(size)
An exact fixed-point number. Decimal(5,2)
Decimal (Size,d) The total number of digits is specified in size.
The number of digits after the decimal point is specified in the d parameter.
The maximum number for size is 65.
The maximum number for d is 30.
The default value for size is 10. The default value for d is 0.
CHARACTER
A FIXED length string (can contain letters, numbers, special characters). Char(10)
Char (size) The size parameter specifies the column length in characters - can be from 0 to 255. Default
is 1
Wastage of extra spaces
Processing is simpler
Varchar (size) / A VARIABLE length string (can contain letters,numbers,special characters) Varchar(10)
Varchar2 (size) The size parameter specifies the maximum column length in characters - can be from 0 to Varchar2(10)
65535
NO wastage of extra space
Processing is complex
DATE
Date A date. Format:YYYY-MM-DD. The supported range is from '1000-01-01' to '9999-12-31' Date
CHAR(size) VARCHAR (size) / VARCHAR2 (size)
A FIXED length string (can contain letters, A VARIABLE length string (can contain letters,
numbers, and special characters). numbers, and special characters).
The size parameter specifies the column length in The size parameter specifies the maximum column
characters - can be from 0 to 255. Default is 1 length in characters - can be from 0 to 65535
Wastage of extra spaces as all data elements may not NO wastage of extra space
use all the space reserved
Processing is simpler. Processing is complex.
Name Char(6) Name Varchar(6)
A V I K A V I K
VARCHAR VARCHAR2
It can store upto 2000bytes of characters It can store upto 4000 bytes of characters
It occupies space for NULL values. It will not occupy any space for NULL values
NULLS
If a column in a record has no value, then column is said to be NULL or to contain a NULL.
A reserved word and a special marker to indicate that a data value doesnot exist in the database.
NULLs can appear in fields of any data type , provided they are not restricted by NOT NULL or
PRIMARY KEY constraint.
NOTE:
Zero and NULL(null) are not equivalent.
Any arithmetic expression containing a NULL, always evaluates to NULL.
For eg.
ADMNO NAME CITY DOB
MARKS 80+0+NULL+60 =NULL
25 - null = null
80 Null - 25 = Null
40 * NULL = NULL
0 NULL * 5.2 = NULL
NULL / 20 = NULL
NULL 10 / NULL = NULL
0/NULL=NULL
60 NULL/0=NULL
COMMENTS
Non executable statements which are ignored.
Statements which are not executed
It can appear anywhere within the code.
Given for documentation purpose.
Begin the comment with / *
Begin the comment with --
Begin the comment with #
POINTS TO REMEMBER…
MySQL is not case sensitive.
You can write commands(instructions to database) in
either uppercase/lowercase/or in a mixed way of both the
cases.
For Eg. If the name of a relation(table) is Student then,
Student, STUDENT,sTUDENT,StUdEnT
will represent same relation.
Underscore is allowed in the naming of a relational
object.
For eg. Following are some of the valid way of naming a
DB(database) object
Student,Stu_dent,Student1,Student_1
represent different but, valid DB objects
COMMANDS, CLAUSES, KEYWORD,ARGUMENTS
Commands instructions to database
Eg.
SELECT name FROM student WHERE marks>80;
Clauses One or More logically distinct parts SELECT name
in a command.
Eg. FROM student (From clause)
WHERE marks>80(Where clause) FROM student
Keyword Certain specific words known by
the language processors WHERE marks>80;
Eg. From,where
Arguments Arguments complete or modify
the meaning of a clause
Eg. name
What are Constraints ????
Integrity Constraints:- (or constraints)
These are certain rules that are applicable on a database at all times.
Integrity constraints determine what all changes are permissible to a database.
Types of Integrity Constraint:-
Primary Key (attribute is set to be the primary key of the table)
Unique (attributes having unique values
Not Null (attributes cannot be left blank or NULL)
Check (attributes are checked for condition)
Default (attributes are given default values if left blank)
Foreign Key (references to the primary key of another table)
Understanding DDL and DML queries
DDL Commands (Data Definition Language)
CREATE: Create commands are used to create schema objects eg. tables, indexes.
DROP: Drop commands are used to delete or remove schema objects eg. tables
ALTER: Alter commands are used to modify or change the definition of already existing schema
objects.
DML Commands (Data Manipulation Language)
INSERT: Insertion of information in the table or schema objects
UPDATE : Modification of data stored in the table or database
DELETE: Deletion of information from the table or schema objects
SELECT: Retrieval of information stored in the table or database
EMP
Empno Ename Job Sal Hiredate Deptno
1001 ABC Clerk 20000 25-10-2006 20
1002 EFG Salesman 25000 12-08-2008 10
1006 XYZ Manager 30000 19-05-2008 30
1003 PQR Analyst 30000 10-07-2007 20
CONTENTS
(LEARNING OUTCOMES)
Practical Approach
LEARNING MySQL QUERIES ON DATABASE
Create Database
Use(i.e Open) a Database
Show Databases
Show tables inside a Database
Drop a database
LEARNING MySQL QUERIES ON TABLES (DDL Queries)
Create a Table
Alter a Table
Drop a Table(i.e Delete a table)
MySQL Queries …. (Practical)
1
2
MySQL Queries on Databases
1) To create a Database Create database IPbatch;
CREATE DATABASE <database name>;
USE IPbatch ;
2) To open or enter a Database
USE <database name>;
Table Table
3) To show all Databases 1 Table 2
Show databases; 3
4) After entering the database, to show all the tables
Show tables;
5) Delete / drop a database
Drop database<database name>
To show all Databases
To create a Database
To see whether the new DB created is shown or not
To use/ open/ enter a Database
After entering the database, to show all the tables
To remove a database
To see whether the Database deleted is removed or not
NOTE: You can use text editors to write your queries and run
later. But, remember to save your file. Eg. Notepad
We have learnt the basic queries for working with a database.
Now, let us learn working with tables i.e. relations in a database.
MySQL Queries on
Tables / Relations
I) Create Table Query
SYNTAX
CREATE TABLE <table_name>
(<column name> <data type> [(<size>)],
<column name> <data type> [(<size>)….]);
To CREATE a TABLE
DEPT with constraints
ERROR!! as no DB selected for USE
Database csip selected for USE
To CREATE a TABLE
DEPT with constraints
To CREATE a
TABLE
student
with constraints
Desc / Describe query
To see the description of the table or to obtain
information about the table structure.
SYNTAX
Desc <table name>;
Or
Describe <table name>;
DDL Queries (contd..)
II) ALTER TABLE QUERY
i) To add a new field to the table
ii) To drop an existing field from the table
iii) To modify or change an existing fields
datatype,size,field name
iv) To add a new constraints to the table
v) To drop an existing constraints from the table
vi) To modify or change an existing fields
constraints
ADMNO SNAME DOB STREAM MARKS DEPTNO
DESCRIPTION SYNTAX of ALTER EXAMPLE
To add a new column ALTER TABLE <table name>
ADD<column name>
<datatype><size> [<constrait name>];
To modify and existing ALTER TABLE <table name>
column’s datatype or MODIFY(column name newdatatype
(newsize)) [FIRST|AFTER column];
size
To change the name of ALTER TABLE <table name>
an existing column CHANGE [COLUMN] old_column_name
new_column_name column_definition;
To drop/delete an ALTER TABLE <table name>
existing column DROP [COLUMN]<column name>
DESCRIPTION SYNTAX of ALTER EXAMPLE
To add a ALTER TABLE <table name>
ADD CONSTRAINT UNIQUE
unique key ( <column_name1>,
constraint <column_name2>…..);
To drop a ALTER TABLE <table name>
DROP Primary key;
primary key
constraint
to a column
To add a ALTER TABLE <table name>
ADD PRIMARY KEY (
primary key <column_name1>,
constraint <column_name2>…..);
to a column
DDL Queries (contd..)
III) Drop a Table (i.e Delete a table)
SYNTAX
DROP TABLE <table name>;
Or
DROP TABLE IF EXISTS <table name>;
CONTENTS-Learning outcomes
QUERIES ON TABLES (DML Queries)
INSERT records in a table
SELECT (To display) a table content
• Select …. FROM
• Select …. DISTINCT / ALL
• Select …. FROM….WHERE
• Select …. With Relational operators
• Select …. With Logical operators
• Select …. IN / NOT IN
• Select …. IS NULL / IS NOT NULL
• Select …. BETWEEN / NOT BETWEEN
• Select …. LIKE / NOT LIKE
• Select …. Using Column Alias
• Select …. Text in Query Output
• Select .... ORDER BY (Asc/ Desc)
UPDATE records in a table
DELETE records from a table
INSERT QUERY
The rows (tuples/ records) are added to a table.
SYNTAX
INSERT INTO <table name> [<column list>]
VALUES (<value>,<value>……) ;
Example:-
Insert Into student Values(105,'Dharna','2004-07-03',"Science",96,10);
Insert Into student(Admno,Sname,DOB) Values(106,'Aman','2003-02-16');
NOTE: Only
those columns
can be
ommitted that
have either
default value or
they allow
NULL values.
SELECT QUERY
Select command is used to retrieve a subset of
rows or columns from one or more tables.
SYNTAX
SELECT <column name> [ ,<column name>,….]
FROM <table name>;
OR
SYNTAX
SELECT <column name> [ ,<column name>,….]
FROM <table name>
WHERE<condition>;
NOTE: To see entire table i.e. everycolumn of the table , then * (asterisk)
can be substituted for a complete list of column.
SELECT Query without WHERE
• Select …. FROM
• Select …. DISTINCT / ALL
• Select …FROM….WHERE
• Select …. With Relational
operators
• Select …. With Logical
operators
• Select …. IN / NOT IN
• Select …. IS NULL /
IS NOT NULL
• Select …. BETWEEN /
NOT BETWEEN
• Select …. LIKE / NOT LIKE
• Select… Using Column Alias
• Select Text in Query Output
• Select .... ORDER BY
( Asc / Desc )
NOTE: The output will be displayed in the same order as the
order of columns given in the SELECT clause of the query
SELECT Query (DISTINCT / ALL)
Distinct
• Select …. FROM Keyword
• Select …. DISTINCT / ALL eliminates
• Select …FROM….WHERE redundant
• Select …. With Relational (duplicate)data
from rows of
operators
the result of the
• Select …. With Logical SELECT
operators statement.
• Select …. IN / NOT IN
• Select …. IS NULL / All keyword
IS NOT NULL
keeps the
redundant
• Select …. BETWEEN / (duplicate)
NOT BETWEEN output rows.
• Select …. LIKE / NOT LIKE NOTE: If you do
• Select… Using Column Alias not specify any
• Select Text in Query Output keyword,
neither distinct
• Select .... ORDER BY nor all, it will be
( Asc / Desc ) treated the
same as All.
SELECT Queries with WHERE clauses
The WHERE clause in SELECT statement specifies the criteria for selection of
• Select …. FROM rows to be returned. The query goes through the entire table one row at a
• Select …. DISTINCT / ALL time and examines each row to determine if the given condition is true.
• Select …FROM….WHERE
• Select …. With Relational
operators
• Select …. With Logical
operators
• Select …. IN / NOT IN
• Select …. IS NULL /
IS NOT NULL
• Select …. BETWEEN /
NOT BETWEEN
• Select …. LIKE / NOT LIKE
• Select… Using Column Alias
• Select Text in Query Output
• Select .... ORDER BY
( Asc / Desc )
SELECT Queries with RELATIONAL OPERATORS
Relational Operators are used to compare two values.
• Select …. FROM The SQL has the following relational operators:
• Select …. DISTINCT / ALL
• Select …FROM….WHERE >, < , >=, <=, = , <> (not equal to) != (not equal to)
The result of the comparison is either True or False.
• Select …. With Relational
operators
• Select …. With Logical
operators
• Select …. IN / NOT IN
• Select …. IS NULL /
IS NOT NULL
• Select …. BETWEEN /
NOT BETWEEN
• Select …. LIKE / NOT LIKE
• Select… Using Column Alias
• Select Text in Query Output
• Select .... ORDER BY
( Asc / Desc )
SELECT Queries with RELATIONAL OPERATORS
• Select …. FROM
• Select …. DISTINCT / ALL
• Select …FROM….WHERE
• Select …. With Relational
operators
• Select …. With Logical
operators
• Select …. IN / NOT IN
• Select …. IS NULL /
IS NOT NULL
• Select …. BETWEEN /
NOT BETWEEN
• Select …. LIKE / NOT LIKE
• Select… Using Column Alias
• Select Text in Query Output
• Select .... ORDER BY
( Asc / Desc )
SELECT Queries with RELATIONAL OPERATORS
• Select …. FROM
• Select …. DISTINCT / ALL
• Select …FROM….WHERE
• Select …. With Relational
operators
• Select …. With Logical
operators
• Select …. IN / NOT IN
• Select …. IS NULL /
IS NOT NULL
• Select …. BETWEEN /
NOT BETWEEN marks!=90
• Select …. LIKE / NOT LIKE
• Select… Using Column Alias
• Select Text in Query Output
• Select .... ORDER BY
( Asc / Desc )
SELECT Queries with RELATIONAL OPERATORS
• Select …. FROM
• Select …. DISTINCT / ALL
• Select …FROM….WHERE
• Select …. With Relational
operators
• Select …. With Logical
operators
• Select …. IN / NOT IN
• Select …. IS NULL /
IS NOT NULL
• Select …. BETWEEN /
NOT BETWEEN
• Select …. LIKE / NOT LIKE
• Select… Using Column Alias
• Select Text in Query Output
• Select .... ORDER BY
( Asc / Desc ) NOTE: The more the date is recent, the greater is its value.
So, more recent dates are greater and older dates are smaller.
The comparison for characters are done alphabetically.
SELECT Queries with Logical operators ( AND, OR, NOT )
Logical operators in
• Select …. FROM MySQL are:
• Select …. DISTINCT / ALL AND(&&),
• Select …FROM….WHERE OR(II), NOT(!)
• Select …. With Relational Logical operators
evaluate to True(1) ,
operators
False(0) , and NULL
• Select …. With Logical values.
operators
• Select …. IN / NOT IN
• Select …. IS NULL /
IS NOT NULL
• Select …. BETWEEN /
NOT BETWEEN
• Select …. LIKE / NOT LIKE
• Select… Using Column Alias
• Select Text in Query Output
• Select .... ORDER BY
( Asc / Desc )
SELECT Queries with Logical operators ( AND, OR, NOT )
• Select …. FROM
• Select …. DISTINCT / ALL
• Select …FROM….WHERE
• Select …. With Relational
operators
• Select …. With Logical
operators
• Select …. IN / NOT IN
• Select …. IS NULL /
IS NOT NULL
• Select …. BETWEEN /
NOT BETWEEN
NOTE: When all the
• Select …. LIKE / NOT LIKE logical operators are
used together, the
• Select… Using Column Alias order of precedence is
• Select Text in Query Output NOT (!)
• Select .... ORDER BY AND(&&)
OR(!!).
( Asc / Desc ) Parenthesis (bracket)
overrides the
precedence order.
SELECT Queries with IN / NOT IN operators (condition based on a list)
For specifying a list of values, IN operator is used. The IN operator
• Select …. FROM selects values that match any value in a given list.
• Select …. DISTINCT / ALL The NOT IN operator finds row that do not match in the list.
• Select …FROM….WHERE
• Select …. With Relational
operators
• Select …. With Logical
operators
• Select …. IN / NOT IN
• Select …. IS NULL /
IS NOT NULL
• Select …. BETWEEN /
NOT BETWEEN
• Select …. LIKE / NOT LIKE
• Select… Using Column Alias
• Select Text in Query Output
• Select .... ORDER BY
( Asc / Desc )
where stream=‘Commerce’ OR stream=‘Arts’; where !(stream=‘Commerce’ OR stream=‘Arts’);
SELECT Queries with IS NULL / IS NOT NULL
IS NULL is used in the where clause to search the NULL value in a
• Select …. FROM column.
• Select …. DISTINCT / ALL IS NOT NULL is used to search the Non-Null values in a column.
• Select …FROM….WHERE Relational operators can’t be used with NULL.
• Select …. With Relational
operators
• Select …. With Logical
operators
• Select …. IN / NOT IN
• Select …. IS NULL /
IS NOT NULL
• Select …. BETWEEN /
NOT BETWEEN
• Select …. LIKE / NOT LIKE
• Select… Using Column Alias
• Select Text in Query Output
• Select .... ORDER BY
( Asc / Desc )
SELECT Queries : BETWEEN/NOT BETWEEN
The BETWEEN operator defines a range of values that the column values
• Select …. FROM must fall into make the condition true.
• Select …. DISTINCT / ALL The NOT BETWEEN Operator is just the opposite of BETWEEN and those
rows which doesn’t satisfy the BETWEEN conditions are retrieved.
• Select …FROM….WHERE
• Select …. With Relational
operators
• Select …. With Logical
operators
• Select …. IN / NOT IN
• Select …. IS NULL /
IS NOT NULL
• Select …. BETWEEN /
NOT BETWEEN
• Select …. LIKE / NOT LIKE
NOTE:
• Select… Using Column Alias NOTE:
BETWEEN NOT BETWEEN
• Select Text in Query Output includes both neither includes
lower value nor
• Select .... ORDER BY lower value and
upper value. upper value
( Asc / Desc )
where( marks >=80 AND marks<=90); where( marks < 80 OR marks > 90);
SELECT Queries : LIKE / NOT LIKE (Pattern matching)
LIKE is a string matching operator , for comparisons on character strings
• Select …. FROM using patterns.
• Select …. DISTINCT / ALL Two wild characters are there
• Select …FROM….WHERE _ (underscore symbol) matches single character
• Select …. With Relational % (percent symbol) matches multiple characters( any substring)
operators
• Select …. With Logical
operators
• Select …. IN / NOT IN
• Select …. IS NULL /
IS NOT NULL
• Select …. BETWEEN /
NOT BETWEEN
• Select …. LIKE / NOT LIKE
• Select… Using Column Alias
• Select Text in Query Output NOTE: NOTE:
• Select .... ORDER BY All the sname
beginning
All the sname
ending with
(Asc / Desc) with ‘A’ ‘A’
SELECT Queries : LIKE / NOT LIKE (Pattern matching)
• Select …. FROM
• Select …. DISTINCT / ALL
• Select …FROM….WHERE
• Select …. With Relational
operators
• Select …. With Logical
operators
• Select …. IN / NOT IN NOTE:
• Select …. IS NULL / Second from last NOTE:
Exactly 4 characters
letter is ‘A’.
starting with ‘A’.
IS NOT NULL It has 1 It has 3 underscores at
underscore at
• Select …. BETWEEN / the end
the end
NOT BETWEEN
• Select …. LIKE / NOT LIKE
• Select… Using Column Alias
• Select Text in Query Output NOTE:
NOTE:
Third letter ‘i’.
• Select .... ORDER BY (Asc/ It has two
All the sname NOT
stating with ‘A’
Desc) underscores in will be retrieved.
the beginning
SELECT Queries : COLUMN ALIAS
Column alias are given in Select query to display the columns with a
• Select …. FROM different name. AS is the keyword used for column alias. But, it is optional if
the alias name is of single word.
• Select …. DISTINCT / ALL Alias means aka. Your nickname is your alias name.
• Select …FROM….WHERE SYNTAX:
• Select …. With Relational SELECT <columnname> AS[columnalias],[,<columnname> AS
[columnalias]]
operators
……
• Select …. With Logical FROM <tablename>;
operators
• Select …. IN / NOT IN
• Select …. IS NULL /
IS NOT NULL
• Select …. BETWEEN /
NOT BETWEEN
NOTE: COLUMN ALIAS
• Select …. LIKE / NOT LIKE
write in ' ' or " "
• Select.. Using Column Alias But, for a single word alias
• Select Text in Query Output name we can omit the quotes.
• Select .. ORDER BY AS is a keyword used for alias
name(As is optional)
(Asc/Desc)
SELECT Queries with TEXT in Query Output
Text, symbols and comments can be inserted in query output to
• Select …. FROM make the OUTPUT more presentable.
• Select …. DISTINCT / ALL
• Select …FROM….WHERE
• Select …. With Relational
operators
• Select …. With Logical
operators
• Select …. IN / NOT IN
• Select …. IS NULL /
IS NOT NULL
• Select …. BETWEEN /
NOT BETWEEN
• Select …. LIKE / NOT LIKE
• Select… Using Column Alias
• Select Text in Query
Output
• Select .... ORDER BY (Asc/
Desc)
SELECT Queries : Sorting results using ORDER BY clause
Usually, the output displayed after the execution of SELECT query is predecided.
• Select …. FROM To sort the result output of a query in a specific order, we use ORDER BY clause.
• Select …. DISTINCT / ALL Sorting can be done in either ascending (asc) or descending (desc) order.
• Select …FROM….WHERE If nothing is mentioned, by default it is done in the default, (ascending) order
• Select …. With
Relational operators
• Select …. With Logical
operators
• Select …. IN / NOT IN
• Select …. IS NULL /
IS NOT NULL
• Select …. BETWEEN /
NOT BETWEEN
• Select …. LIKE / NOT LIKE
• Select… Using Column
Alias
• Select Text in Query
Output
• Select .. ORDER BY
(Asc/ Desc)
SELECT Queries : Sorting results using ORDER BY clause
• Select …. FROM
• Select …. DISTINCT / ALL
• Select …FROM….WHERE
• Select …. With
Relational operators
• Select …. With Logical
operators
• Select …. IN / NOT IN
• Select …. IS NULL /
IS NOT NULL
• Select …. BETWEEN /
NOT BETWEEN
• Select …. LIKE / NOT LIKE
• Select… Using Column
Alias
• Select Text in Query
Output
• Select .. ORDER BY
(Asc/ Desc)
UPDATE QUERY
UPDATE command helps in modifying the values of in an existing
row(tuple/record).
The new data value is given using the SET keyword.
The new data can be a specified constant, an expression or data from
other tables.
WHERE clause is used for the condition which specifies the rows to be
modified
SYNTAX
UPDATE <table name>
SET <columnname=value>
[WHERE<condition>] ;
NOTE: UPDATE query without WHERE condition will affect all the rows of the table.
[WHERE condition is optional.]
UPDATE QUERIES
DELETE QUERY
DELETE command removes/deletes entire record(s) from a table.
No field arguments required because the full row is removed
WHERE clause is used for the condition which specifies the rows to
be deleted
SYNTAX
DELETE FROM <table name>
[WHERE<condition>] ;
NOTE:
DELETE query without WHERE condition will delete all the rows of the table.
But, still the table will exist without any record.
[WHERE condition is optional.]
DELETE QUERIES
Deleting record as per the
condition
Display the entire table
DELETE
command
(DML) Delete all the records from the table
Display the entire table. Table is empty
Vs Display the structure of the table. Table still exist with no records
DROP
command
(DDL) Remove/Drop/ Delete the entire table from the DB.
Display the entire table
Display the structure of the table.