SlideShare a Scribd company logo
1 of 52
STRUCTURE QUERY LANGUAGE
PREPARED BY
Asst.Prof.Santosh Kumar Rath
 SQL stands for Structured Query
Language
 SQL lets you access and manipulate
databases
 SQL is an ANSI (American National
Standards Institute) standard
 SQL can execute queries against a database
 SQL can retrieve data from a database
 SQL can insert records in a database
 SQL can update records in a database
 SQL can delete records from a database
 SQL can create new databases
 SQL can create new tables in a database
 SQL can create stored procedures in a
database
 SQL can create views in a database
 SQL can set permissions on tables, procedures,
and views
 Byte:Allows whole numbers from 0 to 255 1 byte
 Integer: Allows whole numbers between -32,768 and
32,767 2 bytes
 Long: Allows whole numbers between -
2,147,483,648 and 2,147,483,647 4 bytes
 char (size): Holds a fixed length string (can contain
letters, numbers, and special characters). The fixed
size is specified in parenthesis. Can store up to 255
characters
 varchar (size): Holds a variable length string (can
contain letters, numbers, and special characters).
The maximum size is specified in parenthesis. Can
store up to 255 characters
 nchar: Fixed width Unicode string. Maximum 4,000
characters Defined width x 2
 nvarchar : Variable width Unicode string. Maximum
4,000 characters
 numeric(p,s): Fixed precision and scale numbers.
Allows numbers from -10^38 +1 to 10^38 –1.
 The p parameter indicates the maximum total
number of digits that can be stored (both to the left
and to the right of the decimal point). p must be a
value from 1 to 38. Default is 18.
 date :Store a date only. From January 1, 0001 to
December 31, 9999(3 bytes required)
The tables in the following sections provide
a functional summary of SQL statements
and are divided into these categories:
 Data Definition Language (DDL)
Statements
 Data Manipulation Language (DML)
Statements
 Transaction Control Statements(TCL)
 Data Control Language(DCL)
SQL
DDL CREATE,ALTER,DROP
DML INSERT,DELETE,UPDATE
DCL GRANT,REVOKE
DQL SELECT
TCL COMMIT,ROLLBACK,SAVEPOINT
 Data definition language (DDL)
statements let you to perform these
tasks:
 Create, alter, and drop schema objects
 Data manipulation language (DML)
Statements access and manipulate data
in existing schema objects. These
statements do not implicitly commit the
current transaction. The data
manipulation language statements are:
 delete, insert, update, select.
 A data control language (DCL) is syntax
similar to a computer programming
language used to control access to data
stored in a database. In particular, it is a
component of Structured Query
Language (SQL).
 Grant, Revoke,Truncate
 Transaction control statements
manage changes made by DML
statements. The transaction control
statements are:
 Commit, Rollback, Save point
Syntax: CREATETABLETABLE_NAME(
COL_NAME1 DATATYPE(SIZE),
COL_NAME2 DATATYPE(SIZE),
COL_NAME3 DATATYPE(SIZE),
…………………………………………..)
EXAMPLE:TABLE NAME(STUDENT):
CREATETABLE STUDENT(
ROLLNO NUMBER(10),NAMEVARCHAR(25),
AGE NUMBER(5), MARK NUMBER(5),
ADDRESSVARCHAR(20))
Syntax: INSERT INTOTABLE_NAMEVALUES(
‘COL_NAME1’,’COL_NAME2’,’COL_NAME3’,
‘COL_NAME4’,……………..‘COL_NAMEn’)
 EXAMPLE: INSERT INTO STUDENT
VALUES(100,’SATYA’,20, 80,’BANGALORE’)
 RETRIEVETTHE RECORD FROM TABLE
 SELECT * FROMTABLE_NANME
 EXAMPLE: SELECT * FROM STUDENT
QUESTIONS
Q2. CREATETABLE PRODUCT_MASTER
FIELDS ARE PRODUCT_ID,DESCRIPTION,
PROFITPECENT,QUANTITY,
SELLPRICE,COSTPRICE
Q2.(A) INSERT 10 RECORDS INTOTHETABLE.
Q3.(B).RETRIEVETHE ENTIRE CONTENTS OF
THE PRODUCT_MASTERTABLE
ALTER
COMMAND
•ADD COMMAND
•MODIFY COMMAND
•DROP COMMAND
 The ALTER TABLE Statement : The ALTER
TABLE statement is used to add, delete, or
modify columns in an existing table.
To add a column in a table, use the following
syntax:
 ALTERTABLE table_name ADD
(column_name datatype(SIZE))
 EXAMPLE: ALTERTABLE CLIENT_MASTER
ADD(TELPHONE NUMBER(10))
 To delete a column in a table, use
the following
 Syntax :ALTER TABLE table_name
DROP (column_name)
EXAMPLE: ALTER TABLE
CLIENT_MASTER
DROP(TELPHONE)
 To MODIFY column datatype and size
in a table, use the following syntax
 ALTER TABLE table_name MODIFY
(column_name DATATYPE(SIZE))
 EXAMPLE: ALTERTABLE
CLIENT_MASTER
MODIFY(TELPHONE NUMBER(20))
 UPDTAE COMMAND
 DELETE COMMAND
 DROP COMMAND
 RENAMECOMMAND
 The SQL UPDATE Statement :The UPDATE
statement is used to update existing records
in a table.
 Syntax: UPDATE table_name
SET column1=value1,column2=value2,...
WHERE some_column=some_value
 EXAMPLE: UPDATE CLIENT_MASTER SET
TELEPHONE=98657859WHERE
CLIENT_ID=‘C001’
 The SQL DELETE Statement :The DELETE
statement is used to delete rows in a table.
 SQL DELETE Syntax
 DELETE FROM table_name
WHERE some_column=some_value;
 EXAMPLE: DELETE FROM
CLIENT_MASTERWHERE
CLIENT_ID=‘C005’
 The DROPTABLE Statement:The DROP
TABLE statement is used to delete a table.
 DROPTABLE table_name
 EXAMPLE : DROPTABLE CLIENT_MASTER
 RENAMETABLETableName1TO
TableName2 Parameters
 TableName1 Specifies the name of the table
to be renamed.
 TableName2 Specifies the new name of the
table.
 EXAMPLE: RENAME CLIENT_MASTERTO
CLI_MASTER
 WHERE CLAUSE
 DISTINCT CLAUSE
 ORDER BY CLAUSE
 GROUP BY CLASUE
 HAVING CLAUSE
 The SQL WHERE Clause :The WHERE clause is
used to extract only those records that fulfill a
specified criterion.
 SQL WHERE Syntax:SELECT
column_name,column_name
FROM table_name
WHERE column_name operator value;
 EXAMPLE: SELECT * FROM CLIENT_MASTER
WHERE CLIENT_ID=‘C002’;
 The SQL SELECT DISTINCT Statement: In a
table, a column may contain many duplicate
values; and sometimes you only want to list
the different (distinct) values.
 The DISTINCT keyword can be used to return
only distinct (different) values.
 SQL SELECT DISTINCT Syntax:
 SELECT DISTINCT column_name,
column_name FROM table_name;
 The SQL ORDER BY Keyword: The ORDER BY
keyword is used to sort the result-set by one
or more columns.
 The ORDER BY keyword sorts the records in
ascending order by default.To sort the
records in a descending order, you can use
the DESC keyword.
 SQL ORDER BY Syntax:SELECT
column_name,column_name
FROM table_name ORDER BY
olumn_name,column_name ASC|DESC;
 The GROUP BY statement is used in
conjunction with the aggregate functions to
group the result-set by one or more columns.
 SQL GROUP BY Syntax
 SELECT column_name,
aggregate_function(column_name)
FROM table_name
WHERE column_name operator value
GROUP BY column_name;
 Example: SELECT Shippers.ShipperName
FROM Orders GROUP BY ShipperName;
 The HAVING clause was added to SQL because the
WHERE keyword could not be used with aggregate
functions.
 SQL HAVING Syntax: SELECT column_name,
aggregate_function(column_name) FROM
table_name WHERE column_name operator value
GROUP BY column_name HAVING
aggregate_function(column_name) operator value;
 SELECT Employees.LastName, Employees ON
Orders.EmployeeID=Employees.EmployeeID)
GROUP BY LastName HAVING Orders.OrderID > 10;
 The PRIMARY KEY constraint uniquely identifies
each record in a database table.
 Primary keys must contain unique values.
 A primary key column cannot contain NULL
values.
 Each table should have a primary key, and each
table can have only ONE primary key.
 SYNTAX: CREATETABLETABLE_NAME(CPLNAME
DATATYPE(SIZE)PRIMARY KEY,COLNAME2
DATATYPE(SIZE)…….COLNAMEn
DATATYPE(SIZE))
 EXAMPLE: CREATETABLE Persons
(P_Id int NOT NULL PRIMARY KEY,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Address varchar(255),
City varchar(255) )
 A FOREIGN KEY in one table points to a PRIMARY
KEY in another table.
 SYNATX: CREATETABLETAB_NAME(COLNAME
DATATYPE(SIZE) PRIMARY KEY,COLNAME2
DATATYPE(SIZE),……FOREIGNKEY(COLNAME)
REFERENCESTABLENAME(COLNAME))
 EXAMPLE:CREATE TABLE Orders
( O_Id int NOT NULL, OrderNo int NOT NULL,
P_Id int, PRIMARY KEY (O_Id),
FOREIGN KEY (P_Id) REFERENCES Persons(P_Id))
 AGGREGATE FUNCTION
 NUMERIC FUNCTION
 STRING FUNCTION
 Aggregate functions perform a calculation on a set
of values and return a single value. Except for
COUNT, aggregate functions ignore null values.
Aggregate functions are frequently used with the
GROUP BY clause of the SELECT statement.
 MAX: The MAX() function returns the largest value
of the selected column.
SELECT MAX(column_name) FROM table_name;
 MIN:The MIN() function returns the smallest value
of the selected column.
SELECT MIN(column_name) FROM table_name;
 AVG:The AVG() function returns the average value of
a numeric column:
SELECT AVG(column_name) FROM table_name
 SUM:The SUM() function returns the total sum of a
numeric column.
SELECT SUM(column_name) FROM table_name;
 COUNT:The COUNT(column_name) function
returns the number of values (NULL values will not
be counted) of the specified column:
SELECT COUNT(column_name) FROM table_name;
 ABS(): Returns the absolute value of numeric
expression.
ABS() Syntax: SELECT ABS(NO) FROM DUAL
EXAMPLE: SELECT ABS(-12) FROM DUAL
 CEIL(): Returns the smallest integer value that is not less
than passed numeric expression
CEIL() Syntax: SELECT CEIL(NO) FROM DUAL
EXAMPLE: SELECT CEIL(13.5) FROM DUAL
 COS(): Returns the cosine of passed numeric expression.
The numeric expression should be expressed in radians.
SELECT COS(NO) FROM DUAL
EXAMPLE: SELECT COS(30) FROM DUAL
 EXP(): Returns the base of the natural logarithm (e)
raised to the power of passed numeric expression.
 SELECT EXP(NO) FROM DUAL
 EXAMPLE: SELECT EXP(2) FROM DUAL
 FLOOR(): Returns the largest integer value that is not
greater than passed numeric expression.
 SELECT FLOOR(NO) FROM DUAL
EXAMPLE: SELECT FLOOR(13.5) FROM DUAL
 LOG(): Returns the natural logarithm of the passed
numeric expression.
 SELECT LOG(NO) FROM DUAL
EXAMPLE: SELECT LOG(10) FROM DUAL
 MOD(): Returns the remainder of one expression by
diving by another expression.
 SELECT MOD(NO) FROM DUAL
EXAMPLE: SELECT MOD(10) FROM DUAL
 ROUND(): Returns numeric expression rounded to
an integer. Can be used to round an expression to a
number of decimal points
 SELECT ROUND(NO) FROM DUAL
EXAMPLE: SELECT ROUND(10.19) FROM DUAL
 POW(): Returns the value of one expression raised
to the power of another expression
 SELECT POW(NO,NO) FROM DUAL
EXAMPLE: SELECT POW(10,2) FROM DUAL
 LOWER() Returns the argument in lowercase
SELECT LOWER(STRING) FROM DUAL
EXAMPLE: SELECT LOWER(santosh) FROM DUAL
 UPPER() Converts to uppercase
SELECT UPPER(STRING) FROM DUAL
EXAMPLE: SELECT UPPER(COMPUTER) FROM
DUAL
 INITCAP()The first letter of the string is Capital
SELECT INITCAP(STRING) FROM DUAL
EXAMPLE: SELECT INITCAP(santosh) FROM DUAL
 LENGTH() Returns the length of a string in
bytes
 SELECT LENGTH(STRING) FROM DUAL
EXAMPLE: SELECT LENGTH(COMPUTER)
FROM DUAL
 LPAD() Returns the string argument, left-
padded with the specified string
SELECT LPAD(STRING) FROM DUAL
EXAMPLE: SELECT LPAD('hi',4,'??');
FROM DUAL
 RPAD() Appends string the specified number
of times
SELECT RPAD(STRING) FROM DUAL
EXAMPLE: SELECT RPAD('hi',4,’*'); FROM
DUAL
 LTRIM() Removes leading spaces
SELECT LTRIM(' STRING') FROM DUAL;
EXAMPLE:SELECT LTRIM(‘SANTOSH’,3)
FROM DUAL;
 RTRIM() Removes trailing spaces
SELECT RTRIM(' STRING') FROM DUAL;
EXAMPLE:SELECT RTRIM(‘SANTOSH’,3)
FROM DUAL;
 SQL AND & OR Operators : The AND & OR
operators are used to filter records based on
more than one condition. The AND operator
displays a record if both the first condition AND
the second condition are true. The OR operator
displays a record if either the first condition OR
the second condition is true.
 AND Operator Example
 The following SQL statement selects all
customers from the country "Germany" AND the
city "Berlin", in the "Customers" table:
 Example : SELECT * FROM Customers WHERE
Country='Germany‘ AND City='Berlin';
 The following SQL statement selects all
customers from the city "Berlin" OR "München",
in the "Customers" table
 Example: SELECT * FROM Customers
WHERE City='Berlin‘ OR City='München';
 The IN Operator:The IN operator allows
you to specify multiple values in a WHERE
clause.
 SELECT column_name(s)
FROM table_name WHERE column_name
IN (value1,value2,...);
 IN Operator Example: The following SQL
statement selects all customers with a City
of "Paris" or "London":
 Example: SELECT * FROM Customers
WHERE City IN ('Paris','London');
 The SQL BETWEEN Operator:The
BETWEEN operator selects values within a
range.The values can be numbers, text, or
dates.
 SELECT column_name(s)
FROM table_name WHERE column_name
BETWEEN value1 AND value2;
 NOT BETWEEN Operator Example :To display
the products outside the range of the
previous example, use NOT BETWEEN:
 Example: SELECT * FROM Products
WHERE Price NOT BETWEEN 10 AND 20;
 The following SQL statement selects all
products with a Product Name beginning
with any of the letter BETWEEN 'C' and 'M':
 Example : SELECT * FROM Products
WHERE ProductName BETWEEN 'C' AND 'M';
 LIKEThe LIKE operator is used to compare
a value to similar values using wildcard
operators.
 The SQL LIKE Operator :The LIKE operator
is used to search for a specified pattern in a
column.
 SQL LIKE Syntax : SELECT column_name(s)
FROM table_name
WHERE column_name LIKE pattern;
 Example : SELECT * FROM Customers
WHERE City LIKE ‘S%';

More Related Content

What's hot

Creating database using sql commands
Creating database using sql commandsCreating database using sql commands
Creating database using sql commands
Belle Wx
 

What's hot (19)

Database Systems - SQL - DDL Statements (Chapter 3/2)
Database Systems - SQL - DDL Statements (Chapter 3/2)Database Systems - SQL - DDL Statements (Chapter 3/2)
Database Systems - SQL - DDL Statements (Chapter 3/2)
 
Sql dml & tcl 2
Sql   dml & tcl 2Sql   dml & tcl 2
Sql dml & tcl 2
 
SQL
SQLSQL
SQL
 
Commands of DML in SQL
Commands of DML in SQLCommands of DML in SQL
Commands of DML in SQL
 
Ddl commands
Ddl commandsDdl commands
Ddl commands
 
Oracle: DML
Oracle: DMLOracle: DML
Oracle: DML
 
dbms lab manual
dbms lab manualdbms lab manual
dbms lab manual
 
Creating database using sql commands
Creating database using sql commandsCreating database using sql commands
Creating database using sql commands
 
MY SQL
MY SQLMY SQL
MY SQL
 
Sql
SqlSql
Sql
 
Les10 Creating And Managing Tables
Les10 Creating And Managing TablesLes10 Creating And Managing Tables
Les10 Creating And Managing Tables
 
Sql
SqlSql
Sql
 
DML Commands
DML CommandsDML Commands
DML Commands
 
Nested Queries Lecture
Nested Queries LectureNested Queries Lecture
Nested Queries Lecture
 
Sql commands
Sql commandsSql commands
Sql commands
 
SQL DDL
SQL DDLSQL DDL
SQL DDL
 
Database Systems - SQL - DDL Statements (Chapter 3/3)
Database Systems - SQL - DDL Statements (Chapter 3/3)Database Systems - SQL - DDL Statements (Chapter 3/3)
Database Systems - SQL - DDL Statements (Chapter 3/3)
 
Database Management - Lecture 2 - SQL select, insert, update and delete
Database Management - Lecture 2 - SQL select, insert, update and deleteDatabase Management - Lecture 2 - SQL select, insert, update and delete
Database Management - Lecture 2 - SQL select, insert, update and delete
 
Les11 Including Constraints
Les11 Including ConstraintsLes11 Including Constraints
Les11 Including Constraints
 

Viewers also liked

Introduction to Apache Drill - Big Data Bellevue Meetup 20131023
Introduction to Apache Drill - Big Data Bellevue Meetup 20131023Introduction to Apache Drill - Big Data Bellevue Meetup 20131023
Introduction to Apache Drill - Big Data Bellevue Meetup 20131023
Timothy Chen
 
How Google Does Big Data - DevNexus 2014
How Google Does Big Data - DevNexus 2014How Google Does Big Data - DevNexus 2014
How Google Does Big Data - DevNexus 2014
James Chittenden
 
faradays law and its applications ppt
faradays law and its applications pptfaradays law and its applications ppt
faradays law and its applications ppt
Indira Kundu
 

Viewers also liked (13)

BigQuery for the Big Data win
BigQuery for the Big Data winBigQuery for the Big Data win
BigQuery for the Big Data win
 
Interactive big data analytics
Interactive big data analyticsInteractive big data analytics
Interactive big data analytics
 
Lecture 07 - Basic SQL
Lecture 07 - Basic SQLLecture 07 - Basic SQL
Lecture 07 - Basic SQL
 
Basic SQL Part 2
Basic SQL Part 2Basic SQL Part 2
Basic SQL Part 2
 
Introduction to Apache Drill - Big Data Bellevue Meetup 20131023
Introduction to Apache Drill - Big Data Bellevue Meetup 20131023Introduction to Apache Drill - Big Data Bellevue Meetup 20131023
Introduction to Apache Drill - Big Data Bellevue Meetup 20131023
 
SQL Fundamentals
SQL FundamentalsSQL Fundamentals
SQL Fundamentals
 
Sql tutorial
Sql tutorialSql tutorial
Sql tutorial
 
Emerging technologies /frameworks in Big Data
Emerging technologies /frameworks in Big DataEmerging technologies /frameworks in Big Data
Emerging technologies /frameworks in Big Data
 
How Google Does Big Data - DevNexus 2014
How Google Does Big Data - DevNexus 2014How Google Does Big Data - DevNexus 2014
How Google Does Big Data - DevNexus 2014
 
Advanced Sql Training
Advanced Sql TrainingAdvanced Sql Training
Advanced Sql Training
 
TDC2016SP - Trilha BigData
TDC2016SP - Trilha BigDataTDC2016SP - Trilha BigData
TDC2016SP - Trilha BigData
 
Review of SQL
Review of SQLReview of SQL
Review of SQL
 
faradays law and its applications ppt
faradays law and its applications pptfaradays law and its applications ppt
faradays law and its applications ppt
 

Similar to Introduction to sql new

My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptxMy lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
EliasPetros
 
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptxhjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
EliasPetros
 

Similar to Introduction to sql new (20)

Lab
LabLab
Lab
 
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
Unit-1 SQL fundamentals.docx SQL commands used to create table, insert values...
 
Mysql1
Mysql1Mysql1
Mysql1
 
SQL Query
SQL QuerySQL Query
SQL Query
 
DBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptxDBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptx
 
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptxMy lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
 
Database COMPLETE
Database COMPLETEDatabase COMPLETE
Database COMPLETE
 
Mysql
MysqlMysql
Mysql
 
Mysql
MysqlMysql
Mysql
 
Mysql
MysqlMysql
Mysql
 
SQL - DML and DDL Commands
SQL - DML and DDL CommandsSQL - DML and DDL Commands
SQL - DML and DDL Commands
 
unit 1 ppt.pptx
unit 1 ppt.pptxunit 1 ppt.pptx
unit 1 ppt.pptx
 
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptxhjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
 
Module 3
Module 3Module 3
Module 3
 
Chapter 4 Structured Query Language
Chapter 4 Structured Query LanguageChapter 4 Structured Query Language
Chapter 4 Structured Query Language
 
SQL.ppt
SQL.pptSQL.ppt
SQL.ppt
 
Sql
SqlSql
Sql
 
Db1 lecture4
Db1 lecture4Db1 lecture4
Db1 lecture4
 
Data Manipulation Language.pptx
Data Manipulation Language.pptxData Manipulation Language.pptx
Data Manipulation Language.pptx
 
Sql smart reference_by_prasad
Sql smart reference_by_prasadSql smart reference_by_prasad
Sql smart reference_by_prasad
 

More from SANTOSH RATH

Lesson plan proforma database management system
Lesson plan proforma database management systemLesson plan proforma database management system
Lesson plan proforma database management system
SANTOSH RATH
 
Expected questions tc
Expected questions tcExpected questions tc
Expected questions tc
SANTOSH RATH
 
Expected questions tc
Expected questions tcExpected questions tc
Expected questions tc
SANTOSH RATH
 
Module wise format oops questions
Module wise format oops questionsModule wise format oops questions
Module wise format oops questions
SANTOSH RATH
 
( Becs 2208 ) database management system
( Becs 2208 ) database management system( Becs 2208 ) database management system
( Becs 2208 ) database management system
SANTOSH RATH
 
Expected Questions TC
Expected Questions TCExpected Questions TC
Expected Questions TC
SANTOSH RATH
 
Expected questions tc
Expected questions tcExpected questions tc
Expected questions tc
SANTOSH RATH
 
Expected questions for dbms
Expected questions for dbmsExpected questions for dbms
Expected questions for dbms
SANTOSH RATH
 
Expected questions for dbms
Expected questions for dbmsExpected questions for dbms
Expected questions for dbms
SANTOSH RATH
 
Oops model question
Oops model questionOops model question
Oops model question
SANTOSH RATH
 
System programming note
System programming noteSystem programming note
System programming note
SANTOSH RATH
 
Operating system notes
Operating system notesOperating system notes
Operating system notes
SANTOSH RATH
 

More from SANTOSH RATH (20)

Lesson plan proforma database management system
Lesson plan proforma database management systemLesson plan proforma database management system
Lesson plan proforma database management system
 
Lesson plan proforma progrmming in c
Lesson plan proforma progrmming in cLesson plan proforma progrmming in c
Lesson plan proforma progrmming in c
 
Expected questions tc
Expected questions tcExpected questions tc
Expected questions tc
 
Expected questions tc
Expected questions tcExpected questions tc
Expected questions tc
 
Module wise format oops questions
Module wise format oops questionsModule wise format oops questions
Module wise format oops questions
 
2011dbms
2011dbms2011dbms
2011dbms
 
2006dbms
2006dbms2006dbms
2006dbms
 
( Becs 2208 ) database management system
( Becs 2208 ) database management system( Becs 2208 ) database management system
( Becs 2208 ) database management system
 
Rdbms2010
Rdbms2010Rdbms2010
Rdbms2010
 
Expected Questions TC
Expected Questions TCExpected Questions TC
Expected Questions TC
 
Expected questions tc
Expected questions tcExpected questions tc
Expected questions tc
 
Expected questions for dbms
Expected questions for dbmsExpected questions for dbms
Expected questions for dbms
 
Expected questions for dbms
Expected questions for dbmsExpected questions for dbms
Expected questions for dbms
 
Oops model question
Oops model questionOops model question
Oops model question
 
System programming note
System programming noteSystem programming note
System programming note
 
Operating system notes
Operating system notesOperating system notes
Operating system notes
 
Os notes
Os notesOs notes
Os notes
 
OS ASSIGNMENT 2
OS ASSIGNMENT 2OS ASSIGNMENT 2
OS ASSIGNMENT 2
 
OS ASSIGNMENT-1
OS ASSIGNMENT-1OS ASSIGNMENT-1
OS ASSIGNMENT-1
 
OS ASSIGNMENT 3
OS ASSIGNMENT 3OS ASSIGNMENT 3
OS ASSIGNMENT 3
 

Recently uploaded

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Recently uploaded (20)

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 

Introduction to sql new

  • 1. STRUCTURE QUERY LANGUAGE PREPARED BY Asst.Prof.Santosh Kumar Rath
  • 2.
  • 3.  SQL stands for Structured Query Language  SQL lets you access and manipulate databases  SQL is an ANSI (American National Standards Institute) standard
  • 4.  SQL can execute queries against a database  SQL can retrieve data from a database  SQL can insert records in a database  SQL can update records in a database  SQL can delete records from a database  SQL can create new databases  SQL can create new tables in a database  SQL can create stored procedures in a database  SQL can create views in a database  SQL can set permissions on tables, procedures, and views
  • 5.  Byte:Allows whole numbers from 0 to 255 1 byte  Integer: Allows whole numbers between -32,768 and 32,767 2 bytes  Long: Allows whole numbers between - 2,147,483,648 and 2,147,483,647 4 bytes  char (size): Holds a fixed length string (can contain letters, numbers, and special characters). The fixed size is specified in parenthesis. Can store up to 255 characters  varchar (size): Holds a variable length string (can contain letters, numbers, and special characters). The maximum size is specified in parenthesis. Can store up to 255 characters
  • 6.  nchar: Fixed width Unicode string. Maximum 4,000 characters Defined width x 2  nvarchar : Variable width Unicode string. Maximum 4,000 characters  numeric(p,s): Fixed precision and scale numbers. Allows numbers from -10^38 +1 to 10^38 –1.  The p parameter indicates the maximum total number of digits that can be stored (both to the left and to the right of the decimal point). p must be a value from 1 to 38. Default is 18.  date :Store a date only. From January 1, 0001 to December 31, 9999(3 bytes required)
  • 7. The tables in the following sections provide a functional summary of SQL statements and are divided into these categories:  Data Definition Language (DDL) Statements  Data Manipulation Language (DML) Statements  Transaction Control Statements(TCL)  Data Control Language(DCL)
  • 8.
  • 9. SQL DDL CREATE,ALTER,DROP DML INSERT,DELETE,UPDATE DCL GRANT,REVOKE DQL SELECT TCL COMMIT,ROLLBACK,SAVEPOINT
  • 10.  Data definition language (DDL) statements let you to perform these tasks:  Create, alter, and drop schema objects
  • 11.  Data manipulation language (DML) Statements access and manipulate data in existing schema objects. These statements do not implicitly commit the current transaction. The data manipulation language statements are:  delete, insert, update, select.
  • 12.  A data control language (DCL) is syntax similar to a computer programming language used to control access to data stored in a database. In particular, it is a component of Structured Query Language (SQL).  Grant, Revoke,Truncate
  • 13.  Transaction control statements manage changes made by DML statements. The transaction control statements are:  Commit, Rollback, Save point
  • 14.
  • 15. Syntax: CREATETABLETABLE_NAME( COL_NAME1 DATATYPE(SIZE), COL_NAME2 DATATYPE(SIZE), COL_NAME3 DATATYPE(SIZE), …………………………………………..) EXAMPLE:TABLE NAME(STUDENT): CREATETABLE STUDENT( ROLLNO NUMBER(10),NAMEVARCHAR(25), AGE NUMBER(5), MARK NUMBER(5), ADDRESSVARCHAR(20))
  • 17.  RETRIEVETTHE RECORD FROM TABLE  SELECT * FROMTABLE_NANME  EXAMPLE: SELECT * FROM STUDENT
  • 19. Q2. CREATETABLE PRODUCT_MASTER FIELDS ARE PRODUCT_ID,DESCRIPTION, PROFITPECENT,QUANTITY, SELLPRICE,COSTPRICE Q2.(A) INSERT 10 RECORDS INTOTHETABLE. Q3.(B).RETRIEVETHE ENTIRE CONTENTS OF THE PRODUCT_MASTERTABLE
  • 21.  The ALTER TABLE Statement : The ALTER TABLE statement is used to add, delete, or modify columns in an existing table. To add a column in a table, use the following syntax:  ALTERTABLE table_name ADD (column_name datatype(SIZE))  EXAMPLE: ALTERTABLE CLIENT_MASTER ADD(TELPHONE NUMBER(10))
  • 22.  To delete a column in a table, use the following  Syntax :ALTER TABLE table_name DROP (column_name) EXAMPLE: ALTER TABLE CLIENT_MASTER DROP(TELPHONE)
  • 23.  To MODIFY column datatype and size in a table, use the following syntax  ALTER TABLE table_name MODIFY (column_name DATATYPE(SIZE))  EXAMPLE: ALTERTABLE CLIENT_MASTER MODIFY(TELPHONE NUMBER(20))
  • 24.  UPDTAE COMMAND  DELETE COMMAND  DROP COMMAND  RENAMECOMMAND
  • 25.  The SQL UPDATE Statement :The UPDATE statement is used to update existing records in a table.  Syntax: UPDATE table_name SET column1=value1,column2=value2,... WHERE some_column=some_value  EXAMPLE: UPDATE CLIENT_MASTER SET TELEPHONE=98657859WHERE CLIENT_ID=‘C001’
  • 26.  The SQL DELETE Statement :The DELETE statement is used to delete rows in a table.  SQL DELETE Syntax  DELETE FROM table_name WHERE some_column=some_value;  EXAMPLE: DELETE FROM CLIENT_MASTERWHERE CLIENT_ID=‘C005’
  • 27.  The DROPTABLE Statement:The DROP TABLE statement is used to delete a table.  DROPTABLE table_name  EXAMPLE : DROPTABLE CLIENT_MASTER
  • 28.  RENAMETABLETableName1TO TableName2 Parameters  TableName1 Specifies the name of the table to be renamed.  TableName2 Specifies the new name of the table.  EXAMPLE: RENAME CLIENT_MASTERTO CLI_MASTER
  • 29.  WHERE CLAUSE  DISTINCT CLAUSE  ORDER BY CLAUSE  GROUP BY CLASUE  HAVING CLAUSE
  • 30.  The SQL WHERE Clause :The WHERE clause is used to extract only those records that fulfill a specified criterion.  SQL WHERE Syntax:SELECT column_name,column_name FROM table_name WHERE column_name operator value;  EXAMPLE: SELECT * FROM CLIENT_MASTER WHERE CLIENT_ID=‘C002’;
  • 31.  The SQL SELECT DISTINCT Statement: In a table, a column may contain many duplicate values; and sometimes you only want to list the different (distinct) values.  The DISTINCT keyword can be used to return only distinct (different) values.  SQL SELECT DISTINCT Syntax:  SELECT DISTINCT column_name, column_name FROM table_name;
  • 32.  The SQL ORDER BY Keyword: The ORDER BY keyword is used to sort the result-set by one or more columns.  The ORDER BY keyword sorts the records in ascending order by default.To sort the records in a descending order, you can use the DESC keyword.  SQL ORDER BY Syntax:SELECT column_name,column_name FROM table_name ORDER BY olumn_name,column_name ASC|DESC;
  • 33.  The GROUP BY statement is used in conjunction with the aggregate functions to group the result-set by one or more columns.  SQL GROUP BY Syntax  SELECT column_name, aggregate_function(column_name) FROM table_name WHERE column_name operator value GROUP BY column_name;  Example: SELECT Shippers.ShipperName FROM Orders GROUP BY ShipperName;
  • 34.  The HAVING clause was added to SQL because the WHERE keyword could not be used with aggregate functions.  SQL HAVING Syntax: SELECT column_name, aggregate_function(column_name) FROM table_name WHERE column_name operator value GROUP BY column_name HAVING aggregate_function(column_name) operator value;  SELECT Employees.LastName, Employees ON Orders.EmployeeID=Employees.EmployeeID) GROUP BY LastName HAVING Orders.OrderID > 10;
  • 35.  The PRIMARY KEY constraint uniquely identifies each record in a database table.  Primary keys must contain unique values.  A primary key column cannot contain NULL values.  Each table should have a primary key, and each table can have only ONE primary key.  SYNTAX: CREATETABLETABLE_NAME(CPLNAME DATATYPE(SIZE)PRIMARY KEY,COLNAME2 DATATYPE(SIZE)…….COLNAMEn DATATYPE(SIZE))
  • 36.  EXAMPLE: CREATETABLE Persons (P_Id int NOT NULL PRIMARY KEY, LastName varchar(255) NOT NULL, FirstName varchar(255), Address varchar(255), City varchar(255) )
  • 37.  A FOREIGN KEY in one table points to a PRIMARY KEY in another table.  SYNATX: CREATETABLETAB_NAME(COLNAME DATATYPE(SIZE) PRIMARY KEY,COLNAME2 DATATYPE(SIZE),……FOREIGNKEY(COLNAME) REFERENCESTABLENAME(COLNAME))  EXAMPLE:CREATE TABLE Orders ( O_Id int NOT NULL, OrderNo int NOT NULL, P_Id int, PRIMARY KEY (O_Id), FOREIGN KEY (P_Id) REFERENCES Persons(P_Id))
  • 38.  AGGREGATE FUNCTION  NUMERIC FUNCTION  STRING FUNCTION
  • 39.  Aggregate functions perform a calculation on a set of values and return a single value. Except for COUNT, aggregate functions ignore null values. Aggregate functions are frequently used with the GROUP BY clause of the SELECT statement.  MAX: The MAX() function returns the largest value of the selected column. SELECT MAX(column_name) FROM table_name;  MIN:The MIN() function returns the smallest value of the selected column. SELECT MIN(column_name) FROM table_name;
  • 40.  AVG:The AVG() function returns the average value of a numeric column: SELECT AVG(column_name) FROM table_name  SUM:The SUM() function returns the total sum of a numeric column. SELECT SUM(column_name) FROM table_name;  COUNT:The COUNT(column_name) function returns the number of values (NULL values will not be counted) of the specified column: SELECT COUNT(column_name) FROM table_name;
  • 41.  ABS(): Returns the absolute value of numeric expression. ABS() Syntax: SELECT ABS(NO) FROM DUAL EXAMPLE: SELECT ABS(-12) FROM DUAL  CEIL(): Returns the smallest integer value that is not less than passed numeric expression CEIL() Syntax: SELECT CEIL(NO) FROM DUAL EXAMPLE: SELECT CEIL(13.5) FROM DUAL  COS(): Returns the cosine of passed numeric expression. The numeric expression should be expressed in radians. SELECT COS(NO) FROM DUAL EXAMPLE: SELECT COS(30) FROM DUAL
  • 42.  EXP(): Returns the base of the natural logarithm (e) raised to the power of passed numeric expression.  SELECT EXP(NO) FROM DUAL  EXAMPLE: SELECT EXP(2) FROM DUAL  FLOOR(): Returns the largest integer value that is not greater than passed numeric expression.  SELECT FLOOR(NO) FROM DUAL EXAMPLE: SELECT FLOOR(13.5) FROM DUAL  LOG(): Returns the natural logarithm of the passed numeric expression.  SELECT LOG(NO) FROM DUAL EXAMPLE: SELECT LOG(10) FROM DUAL
  • 43.  MOD(): Returns the remainder of one expression by diving by another expression.  SELECT MOD(NO) FROM DUAL EXAMPLE: SELECT MOD(10) FROM DUAL  ROUND(): Returns numeric expression rounded to an integer. Can be used to round an expression to a number of decimal points  SELECT ROUND(NO) FROM DUAL EXAMPLE: SELECT ROUND(10.19) FROM DUAL  POW(): Returns the value of one expression raised to the power of another expression  SELECT POW(NO,NO) FROM DUAL EXAMPLE: SELECT POW(10,2) FROM DUAL
  • 44.  LOWER() Returns the argument in lowercase SELECT LOWER(STRING) FROM DUAL EXAMPLE: SELECT LOWER(santosh) FROM DUAL  UPPER() Converts to uppercase SELECT UPPER(STRING) FROM DUAL EXAMPLE: SELECT UPPER(COMPUTER) FROM DUAL  INITCAP()The first letter of the string is Capital SELECT INITCAP(STRING) FROM DUAL EXAMPLE: SELECT INITCAP(santosh) FROM DUAL
  • 45.  LENGTH() Returns the length of a string in bytes  SELECT LENGTH(STRING) FROM DUAL EXAMPLE: SELECT LENGTH(COMPUTER) FROM DUAL  LPAD() Returns the string argument, left- padded with the specified string SELECT LPAD(STRING) FROM DUAL EXAMPLE: SELECT LPAD('hi',4,'??'); FROM DUAL
  • 46.  RPAD() Appends string the specified number of times SELECT RPAD(STRING) FROM DUAL EXAMPLE: SELECT RPAD('hi',4,’*'); FROM DUAL  LTRIM() Removes leading spaces SELECT LTRIM(' STRING') FROM DUAL; EXAMPLE:SELECT LTRIM(‘SANTOSH’,3) FROM DUAL;  RTRIM() Removes trailing spaces SELECT RTRIM(' STRING') FROM DUAL; EXAMPLE:SELECT RTRIM(‘SANTOSH’,3) FROM DUAL;
  • 47.  SQL AND & OR Operators : The AND & OR operators are used to filter records based on more than one condition. The AND operator displays a record if both the first condition AND the second condition are true. The OR operator displays a record if either the first condition OR the second condition is true.  AND Operator Example  The following SQL statement selects all customers from the country "Germany" AND the city "Berlin", in the "Customers" table:  Example : SELECT * FROM Customers WHERE Country='Germany‘ AND City='Berlin';
  • 48.  The following SQL statement selects all customers from the city "Berlin" OR "München", in the "Customers" table  Example: SELECT * FROM Customers WHERE City='Berlin‘ OR City='München';
  • 49.  The IN Operator:The IN operator allows you to specify multiple values in a WHERE clause.  SELECT column_name(s) FROM table_name WHERE column_name IN (value1,value2,...);  IN Operator Example: The following SQL statement selects all customers with a City of "Paris" or "London":  Example: SELECT * FROM Customers WHERE City IN ('Paris','London');
  • 50.  The SQL BETWEEN Operator:The BETWEEN operator selects values within a range.The values can be numbers, text, or dates.  SELECT column_name(s) FROM table_name WHERE column_name BETWEEN value1 AND value2;
  • 51.  NOT BETWEEN Operator Example :To display the products outside the range of the previous example, use NOT BETWEEN:  Example: SELECT * FROM Products WHERE Price NOT BETWEEN 10 AND 20;  The following SQL statement selects all products with a Product Name beginning with any of the letter BETWEEN 'C' and 'M':  Example : SELECT * FROM Products WHERE ProductName BETWEEN 'C' AND 'M';
  • 52.  LIKEThe LIKE operator is used to compare a value to similar values using wildcard operators.  The SQL LIKE Operator :The LIKE operator is used to search for a specified pattern in a column.  SQL LIKE Syntax : SELECT column_name(s) FROM table_name WHERE column_name LIKE pattern;  Example : SELECT * FROM Customers WHERE City LIKE ‘S%';