SlideShare una empresa de Scribd logo
1 de 94
 SQL is a standard language for accessing and
manipulating databases.
 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
 Divide in different parts
 S.G.A. (system global area)
 User processes
 Redo log files
 Data files
 Archive file

Sr.
1
 Collection of related fields
Sr. Name
1 ABC
 Collection of related Rows
Sr. Name
1 AAA
City contect
Rajkot 1231231230
2 BBB
3 CCC
Surat 1234567890
Vadodra 0987654321
 Collection of related tables
details
Resultsstudents
 Collection of related tables
details
Resultsstudents
 Data base management system,
 No relation between tables.
 No concept op primary key and foreign key.
 RDBMS stands for Relational Database
Management System.
 RDBMS is the basis for SQL, and for all modern
database systems such as MS SQL Server, IBM
DB2, Oracle, MySQL, and Microsoft Access.
 The data in RDBMS is stored in database objects
called tables.
 A table is a collection of related data entries and
it consists of columns and rows.
 A database most often contains one or more
tables. Each table is identified by a name (e.g.
"Customers" or "Orders"). Tables contain
records (rows) with data.
 SQL can be divided into two parts: The Data
Manipulation Language (DML) and the Data
Definition Language (DDL).
 SELECT - extracts data from a database
 UPDATE - updates data in a database
 DELETE - deletes data from a database
 INSERT INTO - inserts new data into a
database
 The DDL part of SQL permits database tables
to be created or deleted. It also defines
indexes (keys), specifies links between tables,
and imposes constraints between tables. The
most important DDL statements in SQL are:
 CREATE DATABASE - creates a new database
 ALTER DATABASE - modifies a database
 CREATE TABLE - creates a new table
 ALTER TABLE - modifies a table
 DROP TABLE - deletes a table
 CREATE INDEX - creates an index (search key)
 DROP INDEX - deletes an index
 The SELECT statement is used to select data
from a database.
 The result is stored in a result table, called
the result-set.
 SQL SELECT Syntax
 SELECT column_name(s) FROM table_name
and
 SELECT * FROM table_name
 The WHERE clause is used to extract only
those records that fulfill a specified criterion.
SQL WHERE Syntax
SELECT column_name(s) FROM table_name
WHERE column_name operator value
 SQL uses single quotes around text values
(most database systems will also accept
double quotes).
 However, numeric values should not be
enclosed in quotes.
 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.
 The ORDER BY keyword is used to sort the result-
set by a specified column.
 The ORDER BY keyword sorts the records in
ascending order by default.
 If you want to sort the records in a descending
order, you can use the DESC keyword.
SQL ORDER BY Syntax
SELECT column_name(s) FROM table_name
 ORDER BY column_name(s) ASC|DESC
 The INSERT INTO statement is used to insert a
new row in a table.
SQL INSERT INTO Syntax
It is possible to write the INSERT INTO statement
in two forms.
The first form doesn't specify the column names
where the data will be inserted, only their values:
INSERT INTO table_name VALUES (value1, value2,
value3,...)
 The UPDATE statement is used to update
existing re
UPDATE table_name SET column1=value,
column2=value2,... WHERE some_column =
some_valuecords in a table
The DELETE statement is used to delete rows in
a table.
SQL DELETE Syntax
DELETE FROM table_name WHERE
some_column=some_value
 The LIKE operator is used to search for a
specified pattern in a column.
 SELECT column_name(s) FROM table_name
WHERE column_name LIKE pattern
 SELECT * FROM Persons
 WHERE City LIKE 's%'
 SQL wildcards can substitute for one or more
characters when searching for data in a database.
 SQL wildcards must be used with the SQL LIKE
operator.
 With SQL, the following wildcards can be used:
 Wildcard Description
 % A substitute for zero or more characters
 _ A substitute for exactly one character
 [charlist] Any single character in charlist
 [^charlist] or
 [!charlist]Any single character not in charlist
 SELECT * FROM Persons WHERE City LIKE '%nes%‘
 SELECT * FROM Persons WHERE City LIKE 'sa%‘
 SELECT * FROM Persons WHERE FirstName LIKE '_la‘
 SELECT * FROM Persons WHERE LastName LIKE
'S_end_on‘
 SELECT * FROM Persons WHERE LastName LIKE '[bsp]%'
 The IN operator allows you to specify multiple
values
 SELECT column_name(s) FROM table_name
 WHERE column_name IN (value1,value2,...) in
a WHERE clause.
 SELECT * FROM Persons WHERE LastName IN
('Hansen','Pettersen')
 The BETWEEN operator selects a range of data
between two values. The values can be
numbers, text, or dates.
 SELECT column_name(s) FROM table_name
 WHERE column_name BETWEEN value1 AND
value2
 SELECT * FROM Persons WHERE LastName
 BETWEEN 'Hansen' AND 'Pettersen'
 You can give a table or a column another
name by using an alias. This can be a good
thing to do if you have very long or complex
table names or column names.
 An alias name could be anything, but usually
it is short.
 For table
 SELECT column_name(s) FROM table_name
AS alias_name
For column
SELECT column_name AS alias_name
FROM table_name
 With out alias query is :
SELECT Product_Orders.OrderID,
Persons.LastName, Persons.FirstName FROM
Persons, Product_Orders WHERE
Persons.LastName='Hansen' AND
Persons.FirstName='Ola'
SELECT po.OrderID, p.LastName, p.FirstName
FROM Persons AS p, Product_Orders AS po
WHERE p.LastName='Hansen' AND
p.FirstName='Ola'
 The JOIN keyword is used in an SQL statement to
query data from two or more tables, based on a
relationship between certain columns in these tables.
 Tables in a database are often related to each other
with keys.
 A primary key is a column (or a combination of
columns) with a unique value for each row. Each
primary key value must be unique within the table.
The purpose is to bind data together, across tables,
without repeating all of the data in every table.
 The INNER JOIN keyword returns rows when
there is at least one match in both tables.
 SELECT column_name(s) FROM table_name1
INNER JOIN table_name2 ON
table_name1.column_name=table_name2.col
umn_name
 The UNION operator is used to combine the
result-set of two or more SELECT statements.
 Notice that each SELECT statement within the
UNION must have the same number of
columns. The columns must also have similar
data types. Also, the columns in each SELECT
statement must be in the same order.
 SELECT column_name(s) FROM table_name1
 UNION
 SELECT column_name(s) FROM table_name2
 The SELECT INTO statement selects data from
one table and inserts it into a different table.
 The SELECT INTO statement is most often used to
create backup copies of tables.
 SQL SELECT INTO Syntax
 We can select all columns into the new table:
 SELECT *
 INTO new_table_name [IN externaldatabase]
 FROM old_tablename
 SELECT LastName,Firstname INTO
Persons_Backup FROM Persons WHERE
City='Sandnes'
 The CREATE DATABASE statement is used to
create a database.
 SQL CREATE DATABASE Syntax
CREATE DATABASE database_name
 The CREATE TABLE statement is used to
create a table in a database.
SQL CREATE TABLE Syntax
CREATE TABLE table_name(column_name1
data_type, column_name2 data_type,
column_name3 data_type, ....)
 Constraints are used to limit the type of data that can
go into a table.
 Constraints can be specified when a table is created
(with the CREATE TABLE statement) or after the table
is created (with the ALTER TABLE statement).
 We will focus on the following constraints:
 NOT NULL
 UNIQUE
 PRIMARY KEY
 FOREIGN KEY
 CHECK
 DEFAULT
 The NOT NULL constraint enforces a column
to NOT accept NULL values.
 The NOT NULL constraint enforces a field to
always contain a value. This means that you
cannot insert a new record, or update a
record without adding a value to this field.
 The following SQL enforces the "P_Id" column
and the "LastName" column to not accept
NULL values:
 CREATE TABLE Persons
 (
 P_Id int NOT NULL,
 LastName varchar(255) NOT NULL,
 FirstName varchar(255),
 Address varchar(255),
 City varchar(255)
 )
 The UNIQUE constraint uniquely identifies each
record in a database table.
 The UNIQUE and PRIMARY KEY constraints both
provide a guarantee for uniqueness for a column
or set of columns.
 A PRIMARY KEY constraint automatically has a
UNIQUE constraint defined on it.
 Note that you can have many UNIQUE constraints
per table, but only one PRIMARY KEY constraint
per table.
 CREATE TABLE Persons
 (
 P_Id int NOT NULL,
 LastName varchar(255) NOT NULL,
 FirstName varchar(255),
 Address varchar(255),
 City varchar(255),
 CONSTRAINT uc_PersonID UNIQUE
(P_Id,LastName)
 )
 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.
 CREATE TABLE Persons
 (
 P_Id int NOT NULL,
 LastName varchar(255) NOT NULL,
 FirstName varchar(255),
 Address varchar(255),
 City varchar(255),
 CONSTRAINT pk_PersonID PRIMARY KEY
(P_Id))
 ALTER TABLE Persons ADD PRIMARY KEY
(P_Id)
 ALTER TABLE Persons DROP PRIMARY KEY
 A FOREIGN KEY in one table points to a
PRIMARY KEY in another table.
 Let's illustrate the foreign key with an
example. Look at the following two tables:
 CREATE TABLE Orders
 ( O_Id int NOT NULL PRIMARY KEY,
OrderNo int NOT NULL, P_Id int FOREIGN KEY
REFERENCES Persons(P_Id) )
 ALTER TABLE Orders ADD FOREIGN KEY (P_Id)
REFERENCES Persons(P_Id)
 The CHECK constraint is used to limit the
value range that can be placed in a column.
 If you define a CHECK constraint on a single
column it allows only certain values for this
column.
 If you define a CHECK constraint on a table it
can limit the values in certain columns based
on values in other columns in the row.
 CREATE TABLE Persons(P_Id int NOT NULL,
LastName varchar(255) NOT NULL, FirstName
varchar(255), Address varchar(255), City
varchar(255), CHECK (P_Id>0))
 ALTER TABLE Persons ADD CHECK (P_Id>0)
 The DEFAULT constraint is used to insert a
default value into a column.
 The default value will be added to all new
records, if no other value is specified.
 CREATE TABLE Persons( P_Id int NOT NULL,
LastName varchar(255) NOT NULL, FirstName
varchar(255), Address varchar(255),
City varchar(255) DEFAULT 'Sandnes' )
 An index can be created in a table to find data
more quickly and efficiently.
 The users cannot see the indexes, they are just
used to speed up searches/queries.
 Note: Updating a table with indexes takes more
time than updating a table without (because the
indexes also need an update). So you should only
create indexes on columns (and tables) that will
be frequently searched against.
 CREATE INDEX Pindex ON Persons (LastName)
 The DROP INDEX statement is used to delete
an index in a table.
 Use to delete object from data base
 Like
 Table
 Index
 Column
 View
 And etc….
 The ALTER TABLE statement is used to add,
delete, or modify columns in an existing
table.
 SQL ALTER TABLE Syntax
 To add a column in a table, use the following
syntax:
 ALTER TABLE table_name
 ADD column_name datatype
 In SQL, a view is a virtual table based on the
result-set of an SQL statement.
 A view contains rows and columns, just like a
real table. The fields in a view are fields from
one or more real tables in the database.
 You can add SQL functions, WHERE, and JOIN
statements to a view and present the data as
if the data were coming from one single
table.
 CREATE VIEW view_name AS SELECT
column_name(s) FROM table_name WHERE
condition
 AVG() - Returns the average value
 COUNT() - Returns the number of rows
 FIRST() - Returns the first value
 LAST() - Returns the last value
 MAX() - Returns the largest value
 MIN() - Returns the smallest value
 SUM() - Returns the sum
 The AVG() function returns the average value
of a numeric column.
 SELECT AVG(column_name) FROM table_name
 The COUNT() function returns the number of
rows that matches a specified criteria.
 Select count(*)from table1 where roll = 1
 The FIRST() function returns the first value of
the selected column.
 SELECT FIRST(column_name) FROM
table_name
 The LAST() function returns the last value of
the selected column.
 SELECT LAST(column_name) FROM
table_name
 The MAX() function returns the largest value
of the selected column.
 SELECT MAX(column_name) FROM table_name
 The MIN() function returns the smallest value
of the selected column.
 SELECT MIN(column_name) FROM table_name
 The SUM() function returns the total sum of a
numeric column.
 SELECT SUM(column_name) FROM table_name
 Aggregate functions often need an added
GROUP BY statement.
 The GROUP BY statement is used in
conjunction with the aggregate functions to
group the result-set by one or more columns.
 SELECT column_name, aggregate_function
(column_name) FROM table_name
 WHERE column_name operator value
 GROUP BY column_name
 SELECT Customer,SUM(OrderPrice) FROM
Orders GROUP BY Customer
 The HAVING clause was added to SQL
because the WHERE keyword could not be
used with aggregate functions.
 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 Customer,SUM(OrderPrice) FROM
Orders GROUP BY Customer HAVING
SUM(OrderPrice)<2000
 UCASE() - Converts a field to upper case
 LCASE() - Converts a field to lower case
 MID() - Extract characters from a text field
 LEN() - Returns the length of a text field
 ROUND() - Rounds a numeric field to the
number of decimals specified
 NOW() - Returns the current system date
and time
 FORMAT() - Formats how a field is to be
displayed
 The UCASE() function converts the value of a
field to uppercase.
 SELECT UCASE(column_name) FROM
table_name
 The LCASE() function converts the value of a
field to lowercase.
SELECT LCASE(column_name) FROM
table_name
 The MID() function is used to extract
characters from a text field.
 SELECT MID(column_name,start[,length])
FROM table_name
 The LEN() function returns the length of the
value in a text field.
 SELECT LEN(column_name) FROM table_name
 The ROUND() function is used to round a
numeric field to the number of decimals
specified.
 SELECT ROUND(column_name,decimals)
FROM table_name
 The NOW() function returns the current
system date and time.
 SELECT NOW() FROM table_name
SQL

Más contenido relacionado

La actualidad más candente (20)

SQL Basics
SQL BasicsSQL Basics
SQL Basics
 
Introduction to-sql
Introduction to-sqlIntroduction to-sql
Introduction to-sql
 
SQL Tutorial - Basic Commands
SQL Tutorial - Basic CommandsSQL Tutorial - Basic Commands
SQL Tutorial - Basic Commands
 
SQL
SQLSQL
SQL
 
Sql joins
Sql joinsSql joins
Sql joins
 
SQL Views
SQL ViewsSQL Views
SQL Views
 
Sql and Sql commands
Sql and Sql commandsSql and Sql commands
Sql and Sql commands
 
SQL Overview
SQL OverviewSQL Overview
SQL Overview
 
SQL Functions and Operators
SQL Functions and OperatorsSQL Functions and Operators
SQL Functions and Operators
 
SQL Server Learning Drive
SQL Server Learning Drive SQL Server Learning Drive
SQL Server Learning Drive
 
sql function(ppt)
sql function(ppt)sql function(ppt)
sql function(ppt)
 
Mysql
MysqlMysql
Mysql
 
SQL JOINS
SQL JOINSSQL JOINS
SQL JOINS
 
Sql operators & functions 3
Sql operators & functions 3Sql operators & functions 3
Sql operators & functions 3
 
Sql operator
Sql operatorSql operator
Sql operator
 
Sql Constraints
Sql ConstraintsSql Constraints
Sql Constraints
 
Chapter 4 Structured Query Language
Chapter 4 Structured Query LanguageChapter 4 Structured Query Language
Chapter 4 Structured Query Language
 
Joins in SQL
Joins in SQLJoins in SQL
Joins in SQL
 
SQL select clause
SQL select clauseSQL select clause
SQL select clause
 
Group By, Order By, and Aliases in SQL
Group By, Order By, and Aliases in SQLGroup By, Order By, and Aliases in SQL
Group By, Order By, and Aliases in SQL
 

Similar a SQL

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) .pptxjainendraKUMAR55
 
Mysql 120831075600-phpapp01
Mysql 120831075600-phpapp01Mysql 120831075600-phpapp01
Mysql 120831075600-phpapp01sagaroceanic11
 
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...SakkaravarthiS1
 
Introduction to sql new
Introduction to sql newIntroduction to sql new
Introduction to sql newSANTOSH RATH
 
SQL Tutorial for Beginners
SQL Tutorial for BeginnersSQL Tutorial for Beginners
SQL Tutorial for BeginnersAbdelhay Shafi
 
Sql smart reference_by_prasad
Sql smart reference_by_prasadSql smart reference_by_prasad
Sql smart reference_by_prasadpaddu123
 
Sql smart reference_by_prasad
Sql smart reference_by_prasadSql smart reference_by_prasad
Sql smart reference_by_prasadpaddu123
 
Sql overview-1232931296681161-1
Sql overview-1232931296681161-1Sql overview-1232931296681161-1
Sql overview-1232931296681161-1sagaroceanic11
 

Similar a SQL (20)

Sql slid
Sql slidSql slid
Sql slid
 
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 SQL
MY SQLMY SQL
MY SQL
 
SQL Query
SQL QuerySQL Query
SQL Query
 
Mysql 120831075600-phpapp01
Mysql 120831075600-phpapp01Mysql 120831075600-phpapp01
Mysql 120831075600-phpapp01
 
SQL report
SQL reportSQL report
SQL report
 
Sql
SqlSql
Sql
 
SQL
SQLSQL
SQL
 
SQL
SQLSQL
SQL
 
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...
 
Query
QueryQuery
Query
 
Introduction to sql new
Introduction to sql newIntroduction to sql new
Introduction to sql new
 
MySQL Essential Training
MySQL Essential TrainingMySQL Essential Training
MySQL Essential Training
 
SQL Tutorial for Beginners
SQL Tutorial for BeginnersSQL Tutorial for Beginners
SQL Tutorial for Beginners
 
Mysql cheatsheet
Mysql cheatsheetMysql cheatsheet
Mysql cheatsheet
 
Module 3
Module 3Module 3
Module 3
 
ADV PPT 2 LAB.pptx
ADV PPT 2 LAB.pptxADV PPT 2 LAB.pptx
ADV PPT 2 LAB.pptx
 
Sql smart reference_by_prasad
Sql smart reference_by_prasadSql smart reference_by_prasad
Sql smart reference_by_prasad
 
Sql smart reference_by_prasad
Sql smart reference_by_prasadSql smart reference_by_prasad
Sql smart reference_by_prasad
 
Sql overview-1232931296681161-1
Sql overview-1232931296681161-1Sql overview-1232931296681161-1
Sql overview-1232931296681161-1
 

Más de Shyam Khant

Más de Shyam Khant (8)

Unit2.data type, operators, control structures
Unit2.data type, operators, control structuresUnit2.data type, operators, control structures
Unit2.data type, operators, control structures
 
Introducing to core java
Introducing to core javaIntroducing to core java
Introducing to core java
 
C++
C++C++
C++
 
Php
PhpPhp
Php
 
C++ theory
C++ theoryC++ theory
C++ theory
 
C Theory
C TheoryC Theory
C Theory
 
Java script
Java scriptJava script
Java script
 
Hashing 1
Hashing 1Hashing 1
Hashing 1
 

Último

_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 

Último (20)

_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 

SQL

  • 1.
  • 2.  SQL is a standard language for accessing and manipulating databases.
  • 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.  Divide in different parts  S.G.A. (system global area)  User processes  Redo log files  Data files  Archive file 
  • 6.
  • 7.
  • 8.
  • 9.
  • 10. Sr. 1
  • 11.  Collection of related fields Sr. Name 1 ABC
  • 12.  Collection of related Rows Sr. Name 1 AAA City contect Rajkot 1231231230 2 BBB 3 CCC Surat 1234567890 Vadodra 0987654321
  • 13.  Collection of related tables details Resultsstudents
  • 14.  Collection of related tables details Resultsstudents
  • 15.  Data base management system,  No relation between tables.  No concept op primary key and foreign key.
  • 16.  RDBMS stands for Relational Database Management System.  RDBMS is the basis for SQL, and for all modern database systems such as MS SQL Server, IBM DB2, Oracle, MySQL, and Microsoft Access.  The data in RDBMS is stored in database objects called tables.  A table is a collection of related data entries and it consists of columns and rows.
  • 17.  A database most often contains one or more tables. Each table is identified by a name (e.g. "Customers" or "Orders"). Tables contain records (rows) with data.
  • 18.  SQL can be divided into two parts: The Data Manipulation Language (DML) and the Data Definition Language (DDL).
  • 19.  SELECT - extracts data from a database  UPDATE - updates data in a database  DELETE - deletes data from a database  INSERT INTO - inserts new data into a database
  • 20.  The DDL part of SQL permits database tables to be created or deleted. It also defines indexes (keys), specifies links between tables, and imposes constraints between tables. The most important DDL statements in SQL are:
  • 21.  CREATE DATABASE - creates a new database  ALTER DATABASE - modifies a database  CREATE TABLE - creates a new table  ALTER TABLE - modifies a table  DROP TABLE - deletes a table  CREATE INDEX - creates an index (search key)  DROP INDEX - deletes an index
  • 22.  The SELECT statement is used to select data from a database.  The result is stored in a result table, called the result-set.  SQL SELECT Syntax  SELECT column_name(s) FROM table_name and  SELECT * FROM table_name
  • 23.  The WHERE clause is used to extract only those records that fulfill a specified criterion. SQL WHERE Syntax SELECT column_name(s) FROM table_name WHERE column_name operator value
  • 24.  SQL uses single quotes around text values (most database systems will also accept double quotes).  However, numeric values should not be enclosed in quotes.
  • 25.  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.
  • 26.  The ORDER BY keyword is used to sort the result- set by a specified column.  The ORDER BY keyword sorts the records in ascending order by default.  If you want to sort the records in a descending order, you can use the DESC keyword. SQL ORDER BY Syntax SELECT column_name(s) FROM table_name  ORDER BY column_name(s) ASC|DESC
  • 27.  The INSERT INTO statement is used to insert a new row in a table. SQL INSERT INTO Syntax It is possible to write the INSERT INTO statement in two forms. The first form doesn't specify the column names where the data will be inserted, only their values: INSERT INTO table_name VALUES (value1, value2, value3,...)
  • 28.  The UPDATE statement is used to update existing re UPDATE table_name SET column1=value, column2=value2,... WHERE some_column = some_valuecords in a table
  • 29. The DELETE statement is used to delete rows in a table. SQL DELETE Syntax DELETE FROM table_name WHERE some_column=some_value
  • 30.  The LIKE operator is used to search for a specified pattern in a column.  SELECT column_name(s) FROM table_name WHERE column_name LIKE pattern  SELECT * FROM Persons  WHERE City LIKE 's%'
  • 31.  SQL wildcards can substitute for one or more characters when searching for data in a database.  SQL wildcards must be used with the SQL LIKE operator.  With SQL, the following wildcards can be used:  Wildcard Description  % A substitute for zero or more characters  _ A substitute for exactly one character  [charlist] Any single character in charlist  [^charlist] or  [!charlist]Any single character not in charlist
  • 32.  SELECT * FROM Persons WHERE City LIKE '%nes%‘  SELECT * FROM Persons WHERE City LIKE 'sa%‘  SELECT * FROM Persons WHERE FirstName LIKE '_la‘  SELECT * FROM Persons WHERE LastName LIKE 'S_end_on‘  SELECT * FROM Persons WHERE LastName LIKE '[bsp]%'
  • 33.  The IN operator allows you to specify multiple values  SELECT column_name(s) FROM table_name  WHERE column_name IN (value1,value2,...) in a WHERE clause.  SELECT * FROM Persons WHERE LastName IN ('Hansen','Pettersen')
  • 34.  The BETWEEN operator selects a range of data between two values. The values can be numbers, text, or dates.  SELECT column_name(s) FROM table_name  WHERE column_name BETWEEN value1 AND value2
  • 35.  SELECT * FROM Persons WHERE LastName  BETWEEN 'Hansen' AND 'Pettersen'
  • 36.  You can give a table or a column another name by using an alias. This can be a good thing to do if you have very long or complex table names or column names.  An alias name could be anything, but usually it is short.
  • 37.  For table  SELECT column_name(s) FROM table_name AS alias_name For column SELECT column_name AS alias_name FROM table_name
  • 38.  With out alias query is : SELECT Product_Orders.OrderID, Persons.LastName, Persons.FirstName FROM Persons, Product_Orders WHERE Persons.LastName='Hansen' AND Persons.FirstName='Ola'
  • 39. SELECT po.OrderID, p.LastName, p.FirstName FROM Persons AS p, Product_Orders AS po WHERE p.LastName='Hansen' AND p.FirstName='Ola'
  • 40.  The JOIN keyword is used in an SQL statement to query data from two or more tables, based on a relationship between certain columns in these tables.  Tables in a database are often related to each other with keys.  A primary key is a column (or a combination of columns) with a unique value for each row. Each primary key value must be unique within the table. The purpose is to bind data together, across tables, without repeating all of the data in every table.
  • 41.  The INNER JOIN keyword returns rows when there is at least one match in both tables.  SELECT column_name(s) FROM table_name1 INNER JOIN table_name2 ON table_name1.column_name=table_name2.col umn_name
  • 42.  The UNION operator is used to combine the result-set of two or more SELECT statements.  Notice that each SELECT statement within the UNION must have the same number of columns. The columns must also have similar data types. Also, the columns in each SELECT statement must be in the same order.
  • 43.  SELECT column_name(s) FROM table_name1  UNION  SELECT column_name(s) FROM table_name2
  • 44.  The SELECT INTO statement selects data from one table and inserts it into a different table.  The SELECT INTO statement is most often used to create backup copies of tables.  SQL SELECT INTO Syntax  We can select all columns into the new table:  SELECT *  INTO new_table_name [IN externaldatabase]  FROM old_tablename
  • 45.  SELECT LastName,Firstname INTO Persons_Backup FROM Persons WHERE City='Sandnes'
  • 46.  The CREATE DATABASE statement is used to create a database.  SQL CREATE DATABASE Syntax CREATE DATABASE database_name
  • 47.  The CREATE TABLE statement is used to create a table in a database. SQL CREATE TABLE Syntax CREATE TABLE table_name(column_name1 data_type, column_name2 data_type, column_name3 data_type, ....)
  • 48.  Constraints are used to limit the type of data that can go into a table.  Constraints can be specified when a table is created (with the CREATE TABLE statement) or after the table is created (with the ALTER TABLE statement).  We will focus on the following constraints:  NOT NULL  UNIQUE  PRIMARY KEY  FOREIGN KEY  CHECK  DEFAULT
  • 49.  The NOT NULL constraint enforces a column to NOT accept NULL values.  The NOT NULL constraint enforces a field to always contain a value. This means that you cannot insert a new record, or update a record without adding a value to this field.  The following SQL enforces the "P_Id" column and the "LastName" column to not accept NULL values:
  • 50.  CREATE TABLE Persons  (  P_Id int NOT NULL,  LastName varchar(255) NOT NULL,  FirstName varchar(255),  Address varchar(255),  City varchar(255)  )
  • 51.  The UNIQUE constraint uniquely identifies each record in a database table.  The UNIQUE and PRIMARY KEY constraints both provide a guarantee for uniqueness for a column or set of columns.  A PRIMARY KEY constraint automatically has a UNIQUE constraint defined on it.  Note that you can have many UNIQUE constraints per table, but only one PRIMARY KEY constraint per table.
  • 52.  CREATE TABLE Persons  (  P_Id int NOT NULL,  LastName varchar(255) NOT NULL,  FirstName varchar(255),  Address varchar(255),  City varchar(255),  CONSTRAINT uc_PersonID UNIQUE (P_Id,LastName)  )
  • 53.  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.
  • 54.  CREATE TABLE Persons  (  P_Id int NOT NULL,  LastName varchar(255) NOT NULL,  FirstName varchar(255),  Address varchar(255),  City varchar(255),  CONSTRAINT pk_PersonID PRIMARY KEY (P_Id))
  • 55.  ALTER TABLE Persons ADD PRIMARY KEY (P_Id)
  • 56.  ALTER TABLE Persons DROP PRIMARY KEY
  • 57.  A FOREIGN KEY in one table points to a PRIMARY KEY in another table.  Let's illustrate the foreign key with an example. Look at the following two tables:
  • 58.  CREATE TABLE Orders  ( O_Id int NOT NULL PRIMARY KEY, OrderNo int NOT NULL, P_Id int FOREIGN KEY REFERENCES Persons(P_Id) )
  • 59.  ALTER TABLE Orders ADD FOREIGN KEY (P_Id) REFERENCES Persons(P_Id)
  • 60.  The CHECK constraint is used to limit the value range that can be placed in a column.  If you define a CHECK constraint on a single column it allows only certain values for this column.  If you define a CHECK constraint on a table it can limit the values in certain columns based on values in other columns in the row.
  • 61.  CREATE TABLE Persons(P_Id int NOT NULL, LastName varchar(255) NOT NULL, FirstName varchar(255), Address varchar(255), City varchar(255), CHECK (P_Id>0))
  • 62.  ALTER TABLE Persons ADD CHECK (P_Id>0)
  • 63.  The DEFAULT constraint is used to insert a default value into a column.  The default value will be added to all new records, if no other value is specified.
  • 64.  CREATE TABLE Persons( P_Id int NOT NULL, LastName varchar(255) NOT NULL, FirstName varchar(255), Address varchar(255), City varchar(255) DEFAULT 'Sandnes' )
  • 65.  An index can be created in a table to find data more quickly and efficiently.  The users cannot see the indexes, they are just used to speed up searches/queries.  Note: Updating a table with indexes takes more time than updating a table without (because the indexes also need an update). So you should only create indexes on columns (and tables) that will be frequently searched against.
  • 66.  CREATE INDEX Pindex ON Persons (LastName)
  • 67.  The DROP INDEX statement is used to delete an index in a table.
  • 68.  Use to delete object from data base  Like  Table  Index  Column  View  And etc….
  • 69.  The ALTER TABLE statement is used to add, delete, or modify columns in an existing table.  SQL ALTER TABLE Syntax  To add a column in a table, use the following syntax:  ALTER TABLE table_name  ADD column_name datatype
  • 70.  In SQL, a view is a virtual table based on the result-set of an SQL statement.  A view contains rows and columns, just like a real table. The fields in a view are fields from one or more real tables in the database.  You can add SQL functions, WHERE, and JOIN statements to a view and present the data as if the data were coming from one single table.
  • 71.  CREATE VIEW view_name AS SELECT column_name(s) FROM table_name WHERE condition
  • 72.
  • 73.  AVG() - Returns the average value  COUNT() - Returns the number of rows  FIRST() - Returns the first value  LAST() - Returns the last value  MAX() - Returns the largest value  MIN() - Returns the smallest value  SUM() - Returns the sum
  • 74.  The AVG() function returns the average value of a numeric column.  SELECT AVG(column_name) FROM table_name
  • 75.  The COUNT() function returns the number of rows that matches a specified criteria.  Select count(*)from table1 where roll = 1
  • 76.  The FIRST() function returns the first value of the selected column.  SELECT FIRST(column_name) FROM table_name
  • 77.  The LAST() function returns the last value of the selected column.  SELECT LAST(column_name) FROM table_name
  • 78.  The MAX() function returns the largest value of the selected column.  SELECT MAX(column_name) FROM table_name
  • 79.  The MIN() function returns the smallest value of the selected column.  SELECT MIN(column_name) FROM table_name
  • 80.  The SUM() function returns the total sum of a numeric column.  SELECT SUM(column_name) FROM table_name
  • 81.  Aggregate functions often need an added GROUP BY statement.  The GROUP BY statement is used in conjunction with the aggregate functions to group the result-set by one or more columns.
  • 82.  SELECT column_name, aggregate_function (column_name) FROM table_name  WHERE column_name operator value  GROUP BY column_name
  • 83.  SELECT Customer,SUM(OrderPrice) FROM Orders GROUP BY Customer
  • 84.  The HAVING clause was added to SQL because the WHERE keyword could not be used with aggregate functions.
  • 85.  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
  • 86.  SELECT Customer,SUM(OrderPrice) FROM Orders GROUP BY Customer HAVING SUM(OrderPrice)<2000
  • 87.  UCASE() - Converts a field to upper case  LCASE() - Converts a field to lower case  MID() - Extract characters from a text field  LEN() - Returns the length of a text field  ROUND() - Rounds a numeric field to the number of decimals specified  NOW() - Returns the current system date and time  FORMAT() - Formats how a field is to be displayed
  • 88.  The UCASE() function converts the value of a field to uppercase.  SELECT UCASE(column_name) FROM table_name
  • 89.  The LCASE() function converts the value of a field to lowercase. SELECT LCASE(column_name) FROM table_name
  • 90.  The MID() function is used to extract characters from a text field.  SELECT MID(column_name,start[,length]) FROM table_name
  • 91.  The LEN() function returns the length of the value in a text field.  SELECT LEN(column_name) FROM table_name
  • 92.  The ROUND() function is used to round a numeric field to the number of decimals specified.  SELECT ROUND(column_name,decimals) FROM table_name
  • 93.  The NOW() function returns the current system date and time.  SELECT NOW() FROM table_name