SlideShare a Scribd company logo
SQL
Ch-2: Structure Query Language
Introduction
•What is SQL?
•Need for SQL
•How to create tables in SQL?
•How to add information to tables?
•SELECT … FROM…WHERE (with aggregate functions)
•GROUP BY ….HAVING
•ORDER BY
•UPDATE AND DELETE Command
•ALTER TABLE AND DROP TABLE Command
•EQUI JOIN
What is SQL?
•SQL (Structured Query Language) is a standard language for
accessing and manipulating databases.
•SQL commands are used to create, transform and retrieve information
from Relational Database Management Systems
•also used to create interface between user and database.
•Need for SQL
• SQL commands are used to implement the following;
•SQL can retrieve ,insert ,update ,delete records
•SQL can create new databases
•SQL can create new tables in a database
•SQL can create views in a database
Using Database
•Create data base :
•Create database <database name>;
• >create database school ;
•Following command is used to use a Database mysql>
USE <database name >;
For ex -
mysql> USE school;
A message will come saying- “database changed”
See the Commands
carefully
CREATE TABLE Command
•CREATE TABLE command is used to create table structure.
•we need to give full information about table such as
number of columns,
type of each column and
constraints (primary key)(Optional)
•The CREATE TABLE command requires:
1)Name of the table,
2) Names of fields,
3)Definitions and constrains for each field(optional)
In SQL, we have the following constraints:
NOT NULL - To check a column cannot store NULL value.
PRIMARY KEY - To check that a column have an unique identity
which helps to find a particular record in a table.
Syntax:
CREATE TABLE <table name>
(<column name1> <data type>[size][constraints],
.
.
<column name n> <data type>[size][constraints]);
Table name : Student
Its about a sql topic for basic structured query language
>CREATE TABLE student
(Adno Numeric (3) primary key,
Name varchar (20) not null,
Class Numeric (2),
Section char (1),
Average Numeric (5)
);
If you want view the structure of the table
Use DESC / DESCRIBE command;
DESC STUDENT ; // DESCRIBE STUDENT;
INSERT INTO Command:
This command is used to add rows in the table,
but can add only one row at a time.
Syntax:
INSERT INTO <table name>
[Column_name1, Column_name2, ......Column_name n]
VALUES (value1,value2,value3,….,value n);
OR
INSERT INTO <table name>
VALUES (value1,value2,value3,….,value n);
Note: [] Option
INSERT INTO student VALUES (111,"Anu Jain", 12,"A", 2500);
Note: If we want to insert values to he selective columns then we have to use this
method
INSERT INTO student (ADNO, Name, CLASS) VALUES (777,' LEENA', 'B');
Its about a sql topic for basic structured query language
Its about a sql topic for basic structured query language
Its about a sql topic for basic structured query language
SELECT Command
This command is used to view table information from SQL database.
By using SELECT command, we can get one or more fields information,
while using *, one can get all fields information.
Syntax:
SELECT (* or field list)
FROM <table name>
[WHERE <condition>];
We can specify any condition using where clause.
Where clause is optional.
Example:
1. Display student table information.
SELECT *
FROM student;
2. To display name and class of student table information.
>SELECT name, class FROM student;
3. To display name of 10th class student information.
SELECT name
FROM student
WHERE class = 10;
Operators used in SQL commands:
Arithmetic operators:
Arithmetic operator takes two operands and performs a mathematical
calculation on them.
They can be used only in SELECT command.
The arithmetic operators used in SQL are:
+ Addition - Subtraction * Multiplication / Division
Its about a sql topic for basic structured query language
Its about a sql topic for basic structured query language
Relational operators:
Relational operators are used to implement comparison
between two operands.
These operators can be used only in 'where clause'.
Relational operators are -
< less than
> greater than
< = less than or equal to
> = greater than or equal to
= equal to
! = not equal to
1. Display students' name, who are paying below 3000 fees.
SELECT name FROM student
WHERE fees<3000;
Output:
Name
Anu Jain
Ajit Kumar
Rohan Sharma
2. Display students' name, who are paying above or equal to 3000 fees.
SELECT name FROM student
WHERE fees>=3000;
Output:
Name
Mohit Sharma
Nandini
3. Display students' information, who are not in class 10
SELECT *
FROM student
WHERE class! = 10;
Logical operators:
Logical operators are also possible only in 'where clause' and
are used to merge more than one condition.
Logical operators are:
AND
OR
NOT
Its about a sql topic for basic structured query language
Its about a sql topic for basic structured query language
LIKE OPERATOR: (Wild card Operator)
LIKE OPERATOR is used to search a value similar to specific pattern in a column
using wildcard operator.
There are two wildcard operators - percentage sign (%) and underscore ( _ ).
The percentage sign represents zero, one, or multiple characters (numbers),
while the underscore represents a single number or character.
The symbols can be used in combinations.
Its about a sql topic for basic structured query language
IN Operator :
The IN operator allows us to specify multiple values in a WHERE clause .
For example:
Display students' information, who are in section A and B.
SELECT * FROM student
WHERE section IN ("A","B");
The BETWEEN operator :
The BETWEEN operator is used to test whether or not a value is "between" the two values
stated after the keyword BETWEEN.
For example:
Display students' information, who are paying fees between 2500 and 3500.
SELECT *
FROM student
WHERE fees BETWEEN 2500 AND 3500;
[Note: In the above Query 2500 and 3500 is also included]
ORDER BY command:
This command is used to arrange values in ascending or descending order.
SELECT *
FROM student
ORDER BY fees ASC;
'asc' for ascending order & ‘desc’ for descending order .
Without asc also the list is displayed with ascending order only.
Its about a sql topic for basic structured query language
Aggregate functions
Aggregate functions are used to implement calculation based upon a particular column.
These functions always return a single value.
Aggregate functions are:
1. SUM()
2. AVG()
3. MAX()
4. MIN()
5. COUNT()
Its about a sql topic for basic structured query language
Its about a sql topic for basic structured query language
GROUP BY
The SQL GROUP BY is a clause that enables SQL aggregate functions for grouping of information.
(ie.GROUP BY clause is used in collaboration with the SELECT statement to arrange identical data
into groups.).
This clause is used whenever aggregate functions by group are required.
For example:
1. Display number of students in each class.
SELECT count (*), class
FROM student
GROUP BY class;
2. Display sum of fees for each class.
SELECT class, sum (fees)
FROM student
GROUP BY class;
Having class:
'where' clause is used only to place condition on the selected columns,
'HAVING' clause is used to place condition on groups created by 'group by' clause, because
here the 'WHERE' clause is not useable.
Example:
Display sum of fees which is more than 5000 for each class
SELECT class, sum (fees)
FROM student
GROUP BY class
HAVING sum (fees)>5000;
DISTINCT :
The DISTINCT keyword is used to remove duplicate values in a particular column.
For example:
Display classes in student table.
SELECT class FROM student;
UPDATE Command :
This command is used to implement modification of the data values.
Syntax:
UPDATE <table name>
SET <column name1>=new value, <column name>=new value etc
[WHERE <condition>];
Example:
1. Increase fees value by 500.
UPDATE student
SET fees = fees + 500;
2. Select * from student ;
Increase the fees value by 100 for adno 222.
UPDATE student
SET fees = fees+100
WHERE adno = 222;
DELETE Command:
This command is used to remove information from a particular row or rows.
Note :
This command will delete only row information but not the structure of the table.
Syntax:
DELETE
FROM <table name>
[WHERE <condition>];
For example:
1. Remove adno 444 information.
DELETE
FROM student
WHERE adno = 444;
2. Select * from student;
2. Remove all records.
DELETE
FROM student;
3. Desc student;
ALTER TABLE command
This command is used to implement modification of the structure of the table.
This is a DDL command.
Using this command, we can add a new column, remove the existing column and
modify data type of existing column.
Syntax:
ALTER TABLE <table name>
[ADD/MODIFY/DROP] <column name>;
For example:
1. Add one new column totalfees with number (10, 2).
ALTER TABLE student
ADD totalfees number(10,2);
2. Change totalfees datatype as number(12,2).
ALTER TABLE student
MODIFY totalfees number(12,2);
3. Remove totalfees column.
ALTER TABLE student DROP totalfees;
DROP Command:
This command is used to remove the entire structure of the table and information.
This is also from the DDL command.
Syntax:
DROP TABLE <table name>;
For example:
Remove the whole structure of student table.
DROP TABLE student;
Equi Join
Equi Joins are used to give information in different tables. It is a special
type of join in which we use only equality operator.
For example
SELECT *
FROM product, customer
WHERE product.product_no = customer. procuct_no;
(or)
SELECT *
FROM product p, customer c
WHERE p.product_no=c.procuct_no;
.
PRODUCT CUSTOMER
Its about a sql topic for basic structured query language
NON EQUI JOIN
The SQL NON EQUI JOIN uses comparison operator instead of the equal sign like >, <,
>=, <= along with conditions.
SYNTAX :
SELECT * FROM table_name1, table_name2
WHERE table_name1.column [> | < |!= | >= | <= ] table_name2.column
>Select * from product p, customer c
where p.pdroduct_no != c.product_no;
PRODUCT CUSTOMER
Its about a sql topic for basic structured query language
Ad

More Related Content

Similar to Its about a sql topic for basic structured query language (20)

SAMPLE QUESTION PAPER (THEORY) CLASS: XII SESSION: 2024-25 COMPUTER SCIENCE...
SAMPLE QUESTION PAPER (THEORY)  CLASS: XII SESSION: 2024-25  COMPUTER SCIENCE...SAMPLE QUESTION PAPER (THEORY)  CLASS: XII SESSION: 2024-25  COMPUTER SCIENCE...
SAMPLE QUESTION PAPER (THEORY) CLASS: XII SESSION: 2024-25 COMPUTER SCIENCE...
MafnithaKK
 
SAMPLE QUESTION PAPER (THEORY) CLASS: XII SESSION: 2024-25 COMPUTER SCIENCE...
SAMPLE QUESTION PAPER (THEORY)  CLASS: XII SESSION: 2024-25  COMPUTER SCIENCE...SAMPLE QUESTION PAPER (THEORY)  CLASS: XII SESSION: 2024-25  COMPUTER SCIENCE...
SAMPLE QUESTION PAPER (THEORY) CLASS: XII SESSION: 2024-25 COMPUTER SCIENCE...
MafnithaKK
 
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
jainendraKUMAR55
 
Structure query language, database course
Structure query language, database courseStructure query language, database course
Structure query language, database course
yunussufyan2024
 
SQL. It education ppt for reference sql process coding
SQL. It education ppt for reference  sql process codingSQL. It education ppt for reference  sql process coding
SQL. It education ppt for reference sql process coding
aditipandey498628
 
DATABASE MANAGMENT SYSTEM (DBMS) AND SQL
DATABASE MANAGMENT SYSTEM (DBMS) AND SQLDATABASE MANAGMENT SYSTEM (DBMS) AND SQL
DATABASE MANAGMENT SYSTEM (DBMS) AND SQL
Dev Chauhan
 
ADVANCE ITT BY PRASAD
ADVANCE ITT BY PRASADADVANCE ITT BY PRASAD
ADVANCE ITT BY PRASAD
PADYALAMAITHILINATHA
 
Sql commands
Sql commandsSql commands
Sql commands
Pooja Dixit
 
SQL Tutorial for Beginners
SQL Tutorial for BeginnersSQL Tutorial for Beginners
SQL Tutorial for Beginners
Abdelhay Shafi
 
Sql smart reference_by_prasad
Sql smart reference_by_prasadSql smart reference_by_prasad
Sql smart reference_by_prasad
paddu123
 
Sql smart reference_by_prasad
Sql smart reference_by_prasadSql smart reference_by_prasad
Sql smart reference_by_prasad
paddu123
 
PPT of Common Table Expression (CTE), Window Functions, JOINS, SubQuery
PPT  of Common Table Expression (CTE), Window Functions, JOINS, SubQueryPPT  of Common Table Expression (CTE), Window Functions, JOINS, SubQuery
PPT of Common Table Expression (CTE), Window Functions, JOINS, SubQuery
Abhishek590097
 
MySQL Essential Training
MySQL Essential TrainingMySQL Essential Training
MySQL Essential Training
HudaRaghibKadhim
 
SQL Query
SQL QuerySQL Query
SQL Query
Imam340267
 
Oracle sql material
Oracle sql materialOracle sql material
Oracle sql material
prathap kumar
 
Lab
LabLab
Lab
neelam_rawat
 
Assg2 b 19121033-converted
Assg2 b 19121033-convertedAssg2 b 19121033-converted
Assg2 b 19121033-converted
SUSHANTPHALKE2
 
Les18
Les18Les18
Les18
Vijay Kumar
 
Interview Questions.pdf
Interview Questions.pdfInterview Questions.pdf
Interview Questions.pdf
TarunKumar893717
 
Commands
CommandsCommands
Commands
Ayushi Goyal
 
SAMPLE QUESTION PAPER (THEORY) CLASS: XII SESSION: 2024-25 COMPUTER SCIENCE...
SAMPLE QUESTION PAPER (THEORY)  CLASS: XII SESSION: 2024-25  COMPUTER SCIENCE...SAMPLE QUESTION PAPER (THEORY)  CLASS: XII SESSION: 2024-25  COMPUTER SCIENCE...
SAMPLE QUESTION PAPER (THEORY) CLASS: XII SESSION: 2024-25 COMPUTER SCIENCE...
MafnithaKK
 
SAMPLE QUESTION PAPER (THEORY) CLASS: XII SESSION: 2024-25 COMPUTER SCIENCE...
SAMPLE QUESTION PAPER (THEORY)  CLASS: XII SESSION: 2024-25  COMPUTER SCIENCE...SAMPLE QUESTION PAPER (THEORY)  CLASS: XII SESSION: 2024-25  COMPUTER SCIENCE...
SAMPLE QUESTION PAPER (THEORY) CLASS: XII SESSION: 2024-25 COMPUTER SCIENCE...
MafnithaKK
 
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
jainendraKUMAR55
 
Structure query language, database course
Structure query language, database courseStructure query language, database course
Structure query language, database course
yunussufyan2024
 
SQL. It education ppt for reference sql process coding
SQL. It education ppt for reference  sql process codingSQL. It education ppt for reference  sql process coding
SQL. It education ppt for reference sql process coding
aditipandey498628
 
DATABASE MANAGMENT SYSTEM (DBMS) AND SQL
DATABASE MANAGMENT SYSTEM (DBMS) AND SQLDATABASE MANAGMENT SYSTEM (DBMS) AND SQL
DATABASE MANAGMENT SYSTEM (DBMS) AND SQL
Dev Chauhan
 
SQL Tutorial for Beginners
SQL Tutorial for BeginnersSQL Tutorial for Beginners
SQL Tutorial for Beginners
Abdelhay Shafi
 
Sql smart reference_by_prasad
Sql smart reference_by_prasadSql smart reference_by_prasad
Sql smart reference_by_prasad
paddu123
 
Sql smart reference_by_prasad
Sql smart reference_by_prasadSql smart reference_by_prasad
Sql smart reference_by_prasad
paddu123
 
PPT of Common Table Expression (CTE), Window Functions, JOINS, SubQuery
PPT  of Common Table Expression (CTE), Window Functions, JOINS, SubQueryPPT  of Common Table Expression (CTE), Window Functions, JOINS, SubQuery
PPT of Common Table Expression (CTE), Window Functions, JOINS, SubQuery
Abhishek590097
 
Assg2 b 19121033-converted
Assg2 b 19121033-convertedAssg2 b 19121033-converted
Assg2 b 19121033-converted
SUSHANTPHALKE2
 

Recently uploaded (20)

*"Sensing the World: Insect Sensory Systems"*
*"Sensing the World: Insect Sensory Systems"**"Sensing the World: Insect Sensory Systems"*
*"Sensing the World: Insect Sensory Systems"*
Arshad Shaikh
 
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptxU3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
Mayuri Chavan
 
What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)
jemille6
 
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
parmarjuli1412
 
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Association for Project Management
 
Botany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic ExcellenceBotany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic Excellence
online college homework help
 
Cultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptxCultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptx
UmeshTimilsina1
 
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Leonel Morgado
 
Drugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdfDrugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdf
crewot855
 
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFAMEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
Dr. Nasir Mustafa
 
spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)
Mohamed Rizk Khodair
 
Final Evaluation.docx...........................
Final Evaluation.docx...........................Final Evaluation.docx...........................
Final Evaluation.docx...........................
l1bbyburrell
 
How To Maximize Sales Performance using Odoo 18 Diverse views in sales module
How To Maximize Sales Performance using Odoo 18 Diverse views in sales moduleHow To Maximize Sales Performance using Odoo 18 Diverse views in sales module
How To Maximize Sales Performance using Odoo 18 Diverse views in sales module
Celine George
 
All About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdfAll About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdf
TechSoup
 
Cultivation Practice of Turmeric in Nepal.pptx
Cultivation Practice of Turmeric in Nepal.pptxCultivation Practice of Turmeric in Nepal.pptx
Cultivation Practice of Turmeric in Nepal.pptx
UmeshTimilsina1
 
The role of wall art in interior designing
The role of wall art in interior designingThe role of wall art in interior designing
The role of wall art in interior designing
meghaark2110
 
Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)
Mohamed Rizk Khodair
 
Cultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptxCultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptx
UmeshTimilsina1
 
How to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 PurchaseHow to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 Purchase
Celine George
 
*"Sensing the World: Insect Sensory Systems"*
*"Sensing the World: Insect Sensory Systems"**"Sensing the World: Insect Sensory Systems"*
*"Sensing the World: Insect Sensory Systems"*
Arshad Shaikh
 
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptxU3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
Mayuri Chavan
 
What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)
jemille6
 
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
parmarjuli1412
 
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Association for Project Management
 
Botany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic ExcellenceBotany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic Excellence
online college homework help
 
Cultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptxCultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptx
UmeshTimilsina1
 
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Leonel Morgado
 
Drugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdfDrugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdf
crewot855
 
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFAMEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
Dr. Nasir Mustafa
 
spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)
Mohamed Rizk Khodair
 
Final Evaluation.docx...........................
Final Evaluation.docx...........................Final Evaluation.docx...........................
Final Evaluation.docx...........................
l1bbyburrell
 
How To Maximize Sales Performance using Odoo 18 Diverse views in sales module
How To Maximize Sales Performance using Odoo 18 Diverse views in sales moduleHow To Maximize Sales Performance using Odoo 18 Diverse views in sales module
How To Maximize Sales Performance using Odoo 18 Diverse views in sales module
Celine George
 
All About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdfAll About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdf
TechSoup
 
Cultivation Practice of Turmeric in Nepal.pptx
Cultivation Practice of Turmeric in Nepal.pptxCultivation Practice of Turmeric in Nepal.pptx
Cultivation Practice of Turmeric in Nepal.pptx
UmeshTimilsina1
 
The role of wall art in interior designing
The role of wall art in interior designingThe role of wall art in interior designing
The role of wall art in interior designing
meghaark2110
 
Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)
Mohamed Rizk Khodair
 
Cultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptxCultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptx
UmeshTimilsina1
 
How to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 PurchaseHow to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 Purchase
Celine George
 
Ad

Its about a sql topic for basic structured query language

  • 1. SQL Ch-2: Structure Query Language Introduction •What is SQL? •Need for SQL •How to create tables in SQL? •How to add information to tables? •SELECT … FROM…WHERE (with aggregate functions) •GROUP BY ….HAVING •ORDER BY •UPDATE AND DELETE Command •ALTER TABLE AND DROP TABLE Command •EQUI JOIN
  • 2. What is SQL? •SQL (Structured Query Language) is a standard language for accessing and manipulating databases. •SQL commands are used to create, transform and retrieve information from Relational Database Management Systems •also used to create interface between user and database. •Need for SQL • SQL commands are used to implement the following; •SQL can retrieve ,insert ,update ,delete records •SQL can create new databases •SQL can create new tables in a database •SQL can create views in a database
  • 3. Using Database •Create data base : •Create database <database name>; • >create database school ; •Following command is used to use a Database mysql> USE <database name >; For ex - mysql> USE school; A message will come saying- “database changed” See the Commands carefully
  • 4. CREATE TABLE Command •CREATE TABLE command is used to create table structure. •we need to give full information about table such as number of columns, type of each column and constraints (primary key)(Optional) •The CREATE TABLE command requires: 1)Name of the table, 2) Names of fields, 3)Definitions and constrains for each field(optional) In SQL, we have the following constraints: NOT NULL - To check a column cannot store NULL value. PRIMARY KEY - To check that a column have an unique identity which helps to find a particular record in a table.
  • 5. Syntax: CREATE TABLE <table name> (<column name1> <data type>[size][constraints], . . <column name n> <data type>[size][constraints]); Table name : Student
  • 7. >CREATE TABLE student (Adno Numeric (3) primary key, Name varchar (20) not null, Class Numeric (2), Section char (1), Average Numeric (5) ); If you want view the structure of the table Use DESC / DESCRIBE command; DESC STUDENT ; // DESCRIBE STUDENT;
  • 8. INSERT INTO Command: This command is used to add rows in the table, but can add only one row at a time. Syntax: INSERT INTO <table name> [Column_name1, Column_name2, ......Column_name n] VALUES (value1,value2,value3,….,value n); OR INSERT INTO <table name> VALUES (value1,value2,value3,….,value n); Note: [] Option INSERT INTO student VALUES (111,"Anu Jain", 12,"A", 2500); Note: If we want to insert values to he selective columns then we have to use this method INSERT INTO student (ADNO, Name, CLASS) VALUES (777,' LEENA', 'B');
  • 12. SELECT Command This command is used to view table information from SQL database. By using SELECT command, we can get one or more fields information, while using *, one can get all fields information. Syntax: SELECT (* or field list) FROM <table name> [WHERE <condition>]; We can specify any condition using where clause. Where clause is optional. Example: 1. Display student table information. SELECT * FROM student;
  • 13. 2. To display name and class of student table information. >SELECT name, class FROM student; 3. To display name of 10th class student information. SELECT name FROM student WHERE class = 10; Operators used in SQL commands: Arithmetic operators: Arithmetic operator takes two operands and performs a mathematical calculation on them. They can be used only in SELECT command. The arithmetic operators used in SQL are: + Addition - Subtraction * Multiplication / Division
  • 16. Relational operators: Relational operators are used to implement comparison between two operands. These operators can be used only in 'where clause'. Relational operators are - < less than > greater than < = less than or equal to > = greater than or equal to = equal to ! = not equal to
  • 17. 1. Display students' name, who are paying below 3000 fees. SELECT name FROM student WHERE fees<3000; Output: Name Anu Jain Ajit Kumar Rohan Sharma 2. Display students' name, who are paying above or equal to 3000 fees. SELECT name FROM student WHERE fees>=3000; Output: Name Mohit Sharma Nandini
  • 18. 3. Display students' information, who are not in class 10 SELECT * FROM student WHERE class! = 10;
  • 19. Logical operators: Logical operators are also possible only in 'where clause' and are used to merge more than one condition. Logical operators are: AND OR NOT
  • 22. LIKE OPERATOR: (Wild card Operator) LIKE OPERATOR is used to search a value similar to specific pattern in a column using wildcard operator. There are two wildcard operators - percentage sign (%) and underscore ( _ ). The percentage sign represents zero, one, or multiple characters (numbers), while the underscore represents a single number or character. The symbols can be used in combinations.
  • 24. IN Operator : The IN operator allows us to specify multiple values in a WHERE clause . For example: Display students' information, who are in section A and B. SELECT * FROM student WHERE section IN ("A","B");
  • 25. The BETWEEN operator : The BETWEEN operator is used to test whether or not a value is "between" the two values stated after the keyword BETWEEN. For example: Display students' information, who are paying fees between 2500 and 3500. SELECT * FROM student WHERE fees BETWEEN 2500 AND 3500; [Note: In the above Query 2500 and 3500 is also included]
  • 26. ORDER BY command: This command is used to arrange values in ascending or descending order. SELECT * FROM student ORDER BY fees ASC; 'asc' for ascending order & ‘desc’ for descending order . Without asc also the list is displayed with ascending order only.
  • 28. Aggregate functions Aggregate functions are used to implement calculation based upon a particular column. These functions always return a single value. Aggregate functions are: 1. SUM() 2. AVG() 3. MAX() 4. MIN() 5. COUNT()
  • 31. GROUP BY The SQL GROUP BY is a clause that enables SQL aggregate functions for grouping of information. (ie.GROUP BY clause is used in collaboration with the SELECT statement to arrange identical data into groups.). This clause is used whenever aggregate functions by group are required. For example: 1. Display number of students in each class. SELECT count (*), class FROM student GROUP BY class; 2. Display sum of fees for each class. SELECT class, sum (fees) FROM student GROUP BY class;
  • 32. Having class: 'where' clause is used only to place condition on the selected columns, 'HAVING' clause is used to place condition on groups created by 'group by' clause, because here the 'WHERE' clause is not useable. Example: Display sum of fees which is more than 5000 for each class SELECT class, sum (fees) FROM student GROUP BY class HAVING sum (fees)>5000;
  • 33. DISTINCT : The DISTINCT keyword is used to remove duplicate values in a particular column. For example: Display classes in student table. SELECT class FROM student;
  • 34. UPDATE Command : This command is used to implement modification of the data values. Syntax: UPDATE <table name> SET <column name1>=new value, <column name>=new value etc [WHERE <condition>]; Example: 1. Increase fees value by 500. UPDATE student SET fees = fees + 500; 2. Select * from student ;
  • 35. Increase the fees value by 100 for adno 222. UPDATE student SET fees = fees+100 WHERE adno = 222;
  • 36. DELETE Command: This command is used to remove information from a particular row or rows. Note : This command will delete only row information but not the structure of the table. Syntax: DELETE FROM <table name> [WHERE <condition>]; For example: 1. Remove adno 444 information. DELETE FROM student WHERE adno = 444; 2. Select * from student;
  • 37. 2. Remove all records. DELETE FROM student; 3. Desc student; ALTER TABLE command This command is used to implement modification of the structure of the table. This is a DDL command. Using this command, we can add a new column, remove the existing column and modify data type of existing column. Syntax: ALTER TABLE <table name> [ADD/MODIFY/DROP] <column name>; For example: 1. Add one new column totalfees with number (10, 2). ALTER TABLE student ADD totalfees number(10,2); 2. Change totalfees datatype as number(12,2). ALTER TABLE student MODIFY totalfees number(12,2); 3. Remove totalfees column. ALTER TABLE student DROP totalfees;
  • 38. DROP Command: This command is used to remove the entire structure of the table and information. This is also from the DDL command. Syntax: DROP TABLE <table name>; For example: Remove the whole structure of student table. DROP TABLE student;
  • 39. Equi Join Equi Joins are used to give information in different tables. It is a special type of join in which we use only equality operator. For example SELECT * FROM product, customer WHERE product.product_no = customer. procuct_no; (or) SELECT * FROM product p, customer c WHERE p.product_no=c.procuct_no;
  • 42. NON EQUI JOIN The SQL NON EQUI JOIN uses comparison operator instead of the equal sign like >, <, >=, <= along with conditions. SYNTAX : SELECT * FROM table_name1, table_name2 WHERE table_name1.column [> | < |!= | >= | <= ] table_name2.column
  • 43. >Select * from product p, customer c where p.pdroduct_no != c.product_no; PRODUCT CUSTOMER
  翻译: