SlideShare a Scribd company logo
1 of 7
1. Select
2. Select with Boolean Exp
3. Select with Numeric Exp
4. Select with Date Exp
5. Create DB
6. Drop DB
7. Use DB
8. Create tab
9. Describe tab
10. Drop tab
11. Insert record
12. Update record(s)
13. Delete record(s)
14. Like clause with Select statement
15. Top clause with Select Statement
16. Order By clause with Select Statement
17. Group By clause with Select Statement
18. Distinct clause with Select Statement
19. Default constraint
20. Identity Property
21. Unique constraint
22. Check constraint
23. Alter Table
24. Primary Key constraint
25. Foreign Key constraint
26. Index
27. Views
28. Equi-Join
29. Natural Join
30. Cross Join
1) Select statement
SELECT column1, column2, columnN FROM table_name;
SQL> SELECT * FROM customers;
SQL> SELECT customerID, customername, city FROM CUSTOMERS;
SELECT column1, column2, columnN
FROM table_name
WHERE [condition] //condition- used logical/comparison operators
SQL>SELECT * FROM OrderDetails where quantity>80;
SELECT column1, column2, columnN
FROM table_name
WHERE [condition1] AND [condition2]...AND [conditionN];
SQL>SELECT * FROM Orders where shipperID>2 and employeeID=4; //and operator
SELECT column1, column2, columnN
FROM table_name
WHERE [CONDITION|EXPRESSION];
2) Boolean Expression
SELECT column1, column2, columnN
FROM table_name
WHERE SINGLE VALUE MATCHING EXPRESSION;
SQL> SELECT * FROM CUSTOMERS WHERE City = 'Berlin';
3) Numeric Expression
SELECT numerical_expression as OPERATION_NAME
[FROM table_name
WHERE CONDITION];
SQL> SELECT (15 + 6) AS ADDITION;
SQL> SELECT COUNT(*) AS "No of Records" FROM CUSTOMERS;
//Built-in fns: avg(), sum()
4) Date Expression
SQL> SELECT CURRENT_TIMESTAMP;
SQL> SELECT GETDATE();
5) Create DB
CREATE DATABASE DatabaseName;
SQL> CREATE DATABASE testDB;
SQL> SHOW DATABASES;
6) Drop DB
DROP DATABASE DatabaseName;
SQL> DROP DATABASE testDB;
SQL> SHOW DATABASES;
7) Use DB
USE DatabaseName;
SQL> SHOW DATABASES;
SQL> USE testDB;
8) Create Table
CREATE TABLE table_name(
column1 datatype,
column2 datatype,
column3 datatype,
.....
columnN datatype,
PRIMARY KEY( one or more columns )
);
SQL> CREATE TABLE CUSTOMERS(
ID INT NOT NULL,
NAME VARCHAR (20) NOT NULL,
AGE INT NOT NULL,
ADDRESS CHAR (25) ,
SALARY DECIMAL (18, 2),
PRIMARY KEY (ID)
);
SQL> create table sample (age int, name varchar(20) default 'Tanya');
SQL> insert into sample (age) values (20);
SQL> DESC CUSTOMERS;
9) Describe Table
SQL> DESC CUSTOMERS;
10) Drop Table
DROP TABLE table_name;
SQL> DESC CUSTOMERS;
SQL> DROP TABLE CUSTOMERS;
SQL> DESC CUSTOMERS;
11) Insert Record (Specific Columns or all Columns in a Record, Populate table using another table)
INSERT INTO TABLE_NAME (column1, column2, column3,...columnN)
VALUES (value1, value2, value3,...valueN);
SQL> INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY) VALUES (6, 'Komal', 22, 'MP', 4500.00 );
INSERT INTO TABLE_NAME VALUES (value1,value2,value3,...valueN);
SQL> INSERT INTO CUSTOMERS VALUES (7, 'Muffy', 24, 'Indore', 10000.00 );
INSERT INTO first_table_name [(column1, column2, ... columnN)]
SELECT column1, column2, ...columnN
FROM second_table_name
[WHERE condition];
12) Update Record(s)
UPDATE table_name
SET column1 = value1, column2 = value2...., columnN = valueN
WHERE [condition];
SQL> UPDATE CUSTOMERS SET ADDRESS = 'Pune' WHERE ID = 6;
UPDATE table_name
SET column1 = value1, column2 = value2...., columnN = valueN;
SQL> UPDATE CUSTOMERS SET ADDRESS = 'Pune', SALARY = 1000.00;
13) Delete Record(s)
DELETE FROM table_name
WHERE [condition];
SQL> DELETE FROM CUSTOMERS WHERE ID = 6;
DELETE FROM table_name;
SQL> DELETE FROM CUSTOMERS;
14) Like clause with Select statement
Finds any values that start with XXXX
SELECT FROM table_name WHERE column LIKE 'XXXX%';
SELECT * FROM Customers where postalcode like '0%';
Finds any values that end with XXXX
SELECT FROM table_name WHERE column LIKE '%XXXX';
SELECT * FROM Customers where postalcode like '%3';
Finds any values that have XXXX in any position
SELECT FROM table_name WHERE column LIKE '%XXXX%';
SELECT * FROM Products where productname like '%bo%';
Finds any values that have XXXX in certain positions
SELECT FROM table_name WHERE column LIKE '_XXXX%';
SELECT * FROM Suppliers where phone like '_1%';
SELECT * FROM Suppliers where phone like '_1%2';
15) Top clause with Select Statement to fetch few records
SELECT TOP number|percent column_name(s)
FROM table_name
WHERE [condition]
SQL> SELECT TOP 3 * FROM CUSTOMERS;
SQL> SELECT * FROM CUSTOMERS LIMIT 3; //MySQL
SQL> SELECT * FROM CUSTOMERS WHERE ROWNUM <= 3; //Oracle
16) Order By clause with Select Statement to sort
SELECT column-list
FROM table_name
[WHERE condition]
[ORDER BY column1, column2, .. columnN] [ASC | DESC];
SQL> SELECT * FROM CUSTOMERS order by country, city; // Ascending order is default
SELECT * FROM CUSTOMERS order by country, city DESC;
17) Group By clause with Select Statement to arrange identical data into groups
SELECT column1, column2
FROM table_name
WHERE [ conditions ]
GROUP BY column1, column2
ORDER BY column1, column2
SQL> SELECT * FROM OrderDetails order by ProductID;
SQL> SELECT ProductID, SUM(Quantity) FROM OrderDetails GROUP BY ProductID;
SQL> SELECT ProductID, SUM(Quantity) FROM OrderDetails GROUP BY ProductID order by
Sum(Quantity);
18) Distinct clause with Select Statement to eliminate all the duplicate records and
fetching only unique records
SELECT DISTINCT column1, column2,.....columnN
FROM table_name
WHERE [condition]
SQL> SELECT * FROM Suppliers order by Country;
SQL> SELECT Distinct Country, SupplierName, ContactName, City, Phone FROM Suppliers
order by Country;
19) DEFAULT constraint
SQL> CREATE TABLE users (NAME char(20), AGE integer,
PROFESSION varchar(30) DEFAULT "Student");
SQL>INSERT INTO users (NAME, AGE) VALUES ('ALAN', 36);
SQL> CREATE TABLE users (NAME char(20), AGE integer,
PROFESSION varchar(30) DEFAULT "Student");
SQL>INSERT INTO users (NAME, AGE) VALUES ('ALAN', 36);
SQL> CREATE TABLE Order21 (
ID int NOT NULL,
OrderNumber int NOT NULL,
OrderDate date DEFAULT GETDATE()
);
SQL> INSERT INTO Order21 (ID, OrderNumber) VALUES (20, 201);
20) IDENTITY property OF COLUMN
SQL> CREATE TABLE dept (DEPTNO smallint NOT NULL IDENTITY (500, 1),
DEPTNAME varchar(36) NOT NULL, DEPTID smallint NOT NULL, LOCATION char(30));
SQL> INSERT INTO dept (DEPTNAME, DEPTID) VALUES ('MECH', 20);
SQL> INSERT INTO dept (DEPTNAME, DEPTID, LOCATION) VALUES ('CSE', 10, 'INDIA');
21) UNIQUE constraint
SQL> CREATE TABLE Persons (ID int NOT NULL UNIQUE,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Age int);
SQL> INSERT INTO Persons (ID, LastName, Age) VALUES (100, 'BROWN', 20);
SQL> INSERT INTO Persons (ID, LastName, Age) VALUES (100, 'RED', 20); ………………ERROR
22) Check constraint
SQL> CREATE TABLE employee (ID integer NOT NULL,
NAME varchar(9),
DEPT smallint CHECK (DEPT BETWEEN 10 AND 100),
JOB char(5) CHECK (JOB IN ('Sales', 'IT', 'Clerk')),
HIREDATE DATE, SALARY DECIMAL(7,2),
CONSTRAINT YEARSAL CHECK (YEAR(HIREDATE) > 2000 OR SALARY>10000)
);
SQL> INSERT INTO employee (ID, DEPT, JOB, HIREDATE, SALARY)
VALUES (100, 55, 'Sales', 1995, 12000);
SQL> INSERT INTO employee (ID, DEPT, JOB, HIREDATE, SALARY)
VALUES (100, 55, 'Sales', 1995, 9000); ………………ERROR
SQL> INSERT INTO employee (ID, DEPT, JOB, HIREDATE, SALARY)
VALUES (100, 200, 'Sales', 1995, 9000); ………………ERROR
SQL> INSERT INTO employee (ID, DEPT, JOB, HIREDATE, SALARY)
VALUES (100, 200, ‘Sale', 1995, 9000); ………………ERROR
23) Alter table
SQL> CREATE TABLE employee (ID integer NOT NULL,
NAME varchar(9),
DEPT smallint CHECK (DEPT BETWEEN 10 AND 100),
JOB char(5) CHECK (JOB IN ('Sales', 'IT', 'Clerk')),
HIREDATE DATE, SALARY DECIMAL(7,2),
CONSTRAINT YEARSAL CHECK (YEAR(HIREDATE) > 2000 OR SALARY>10000)
);
SQL> ALTER TABLE employee DROP COLUMN NAME;
SQL> ALTER TABLE employee ADD COLUMN NAME varchar(9);
24) Primary Key Constraint
SQL> CREATE TABLE personnel (
ID int NOT NULL PRIMARY KEY,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Age int
);
SQL> CREATE TABLE personnel1 (
ID int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Age int,
CONSTRAINT PK_Person PRIMARY KEY (ID,LastName)
);
25) Foreign Key Constraint
SQL> CREATE TABLE personnel (
ID int NOT NULL PRIMARY KEY,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Age int
);
SQL> CREATE TABLE Order (
OrderID int NOT NULL PRIMARY KEY,
OrderNumber int NOT NULL,
ID int FOREIGN KEY REFERENCES personnel(ID)
);
26) Index Constraint
SQL> CREATE INDEX index_id ON Order21 (ID);
27) Views
SQL> CREATE TABLE personnel (
ID int NOT NULL PRIMARY KEY,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Age int
);
SQL> INSERT INTO personnel (ID, LastName, FirstName, Age)
VALUES (10, 'BROWN', 'TIM', 28);
SQL> CREATE VIEW myview1 AS SELECT ID, FirstName FROM personnel;
SQL> SELECT * FROM myview1;
28)Equi-Join
Select * FROM student, enrollment
WHERE student.enrollment_no = enrollment.enrollment_no;
(or)
Select * FROM student
INNER JOIN enrollment
ON student.enrollment_no = enrollment.enrollment_no;
29) Natural Join
SELECT *
FROM student
NATURAL JOIN enrollment;
30) Cross Join
SELECT *
FROM student, enrollment;

More Related Content

What's hot

DBMSArchitecture_QueryProcessingandOptimization.pdf
DBMSArchitecture_QueryProcessingandOptimization.pdfDBMSArchitecture_QueryProcessingandOptimization.pdf
DBMSArchitecture_QueryProcessingandOptimization.pdfChristalin Nelson
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 
Tanel Poder - Performance stories from Exadata Migrations
Tanel Poder - Performance stories from Exadata MigrationsTanel Poder - Performance stories from Exadata Migrations
Tanel Poder - Performance stories from Exadata MigrationsTanel Poder
 
Understanding SQL Trace, TKPROF and Execution Plan for beginners
Understanding SQL Trace, TKPROF and Execution Plan for beginnersUnderstanding SQL Trace, TKPROF and Execution Plan for beginners
Understanding SQL Trace, TKPROF and Execution Plan for beginnersCarlos Sierra
 
Tanel Poder - Scripts and Tools short
Tanel Poder - Scripts and Tools shortTanel Poder - Scripts and Tools short
Tanel Poder - Scripts and Tools shortTanel Poder
 
Oracle 21c: New Features and Enhancements of Data Pump & TTS
Oracle 21c: New Features and Enhancements of Data Pump & TTSOracle 21c: New Features and Enhancements of Data Pump & TTS
Oracle 21c: New Features and Enhancements of Data Pump & TTSChristian Gohmann
 
Survey of some free Tools to enhance your SQL Tuning and Performance Diagnost...
Survey of some free Tools to enhance your SQL Tuning and Performance Diagnost...Survey of some free Tools to enhance your SQL Tuning and Performance Diagnost...
Survey of some free Tools to enhance your SQL Tuning and Performance Diagnost...Carlos Sierra
 
Chasing the optimizer
Chasing the optimizerChasing the optimizer
Chasing the optimizerMauro Pagano
 
Same plan different performance
Same plan different performanceSame plan different performance
Same plan different performanceMauro Pagano
 
Oracle Performance Tools of the Trade
Oracle Performance Tools of the TradeOracle Performance Tools of the Trade
Oracle Performance Tools of the TradeCarlos Sierra
 
Understanding my database through SQL*Plus using the free tool eDB360
Understanding my database through SQL*Plus using the free tool eDB360Understanding my database through SQL*Plus using the free tool eDB360
Understanding my database through SQL*Plus using the free tool eDB360Carlos Sierra
 
SQL Plan Directives explained
SQL Plan Directives explainedSQL Plan Directives explained
SQL Plan Directives explainedMauro Pagano
 
Database performance tuning and query optimization
Database performance tuning and query optimizationDatabase performance tuning and query optimization
Database performance tuning and query optimizationDhani Ahmad
 
Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...
Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...
Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...Aaron Shilo
 
Indexing Structures in Database Management system.pdf
Indexing Structures in Database Management system.pdfIndexing Structures in Database Management system.pdf
Indexing Structures in Database Management system.pdfChristalin Nelson
 
Stop the Chaos! Get Real Oracle Performance by Query Tuning Part 1
Stop the Chaos! Get Real Oracle Performance by Query Tuning Part 1Stop the Chaos! Get Real Oracle Performance by Query Tuning Part 1
Stop the Chaos! Get Real Oracle Performance by Query Tuning Part 1SolarWinds
 
Exadata master series_asm_2020
Exadata master series_asm_2020Exadata master series_asm_2020
Exadata master series_asm_2020Anil Nair
 
Optimizing queries MySQL
Optimizing queries MySQLOptimizing queries MySQL
Optimizing queries MySQLGeorgi Sotirov
 
Tuning SQL for Oracle Exadata: The Good, The Bad, and The Ugly Tuning SQL fo...
 Tuning SQL for Oracle Exadata: The Good, The Bad, and The Ugly Tuning SQL fo... Tuning SQL for Oracle Exadata: The Good, The Bad, and The Ugly Tuning SQL fo...
Tuning SQL for Oracle Exadata: The Good, The Bad, and The Ugly Tuning SQL fo...Enkitec
 

What's hot (20)

DBMSArchitecture_QueryProcessingandOptimization.pdf
DBMSArchitecture_QueryProcessingandOptimization.pdfDBMSArchitecture_QueryProcessingandOptimization.pdf
DBMSArchitecture_QueryProcessingandOptimization.pdf
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 
Tanel Poder - Performance stories from Exadata Migrations
Tanel Poder - Performance stories from Exadata MigrationsTanel Poder - Performance stories from Exadata Migrations
Tanel Poder - Performance stories from Exadata Migrations
 
Understanding SQL Trace, TKPROF and Execution Plan for beginners
Understanding SQL Trace, TKPROF and Execution Plan for beginnersUnderstanding SQL Trace, TKPROF and Execution Plan for beginners
Understanding SQL Trace, TKPROF and Execution Plan for beginners
 
Tanel Poder - Scripts and Tools short
Tanel Poder - Scripts and Tools shortTanel Poder - Scripts and Tools short
Tanel Poder - Scripts and Tools short
 
Oracle 21c: New Features and Enhancements of Data Pump & TTS
Oracle 21c: New Features and Enhancements of Data Pump & TTSOracle 21c: New Features and Enhancements of Data Pump & TTS
Oracle 21c: New Features and Enhancements of Data Pump & TTS
 
Survey of some free Tools to enhance your SQL Tuning and Performance Diagnost...
Survey of some free Tools to enhance your SQL Tuning and Performance Diagnost...Survey of some free Tools to enhance your SQL Tuning and Performance Diagnost...
Survey of some free Tools to enhance your SQL Tuning and Performance Diagnost...
 
Chasing the optimizer
Chasing the optimizerChasing the optimizer
Chasing the optimizer
 
Same plan different performance
Same plan different performanceSame plan different performance
Same plan different performance
 
Oracle Performance Tools of the Trade
Oracle Performance Tools of the TradeOracle Performance Tools of the Trade
Oracle Performance Tools of the Trade
 
Understanding my database through SQL*Plus using the free tool eDB360
Understanding my database through SQL*Plus using the free tool eDB360Understanding my database through SQL*Plus using the free tool eDB360
Understanding my database through SQL*Plus using the free tool eDB360
 
SQL Plan Directives explained
SQL Plan Directives explainedSQL Plan Directives explained
SQL Plan Directives explained
 
Database performance tuning and query optimization
Database performance tuning and query optimizationDatabase performance tuning and query optimization
Database performance tuning and query optimization
 
Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...
Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...
Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...
 
Indexing Structures in Database Management system.pdf
Indexing Structures in Database Management system.pdfIndexing Structures in Database Management system.pdf
Indexing Structures in Database Management system.pdf
 
Stop the Chaos! Get Real Oracle Performance by Query Tuning Part 1
Stop the Chaos! Get Real Oracle Performance by Query Tuning Part 1Stop the Chaos! Get Real Oracle Performance by Query Tuning Part 1
Stop the Chaos! Get Real Oracle Performance by Query Tuning Part 1
 
Advanced sql
Advanced sqlAdvanced sql
Advanced sql
 
Exadata master series_asm_2020
Exadata master series_asm_2020Exadata master series_asm_2020
Exadata master series_asm_2020
 
Optimizing queries MySQL
Optimizing queries MySQLOptimizing queries MySQL
Optimizing queries MySQL
 
Tuning SQL for Oracle Exadata: The Good, The Bad, and The Ugly Tuning SQL fo...
 Tuning SQL for Oracle Exadata: The Good, The Bad, and The Ugly Tuning SQL fo... Tuning SQL for Oracle Exadata: The Good, The Bad, and The Ugly Tuning SQL fo...
Tuning SQL for Oracle Exadata: The Good, The Bad, and The Ugly Tuning SQL fo...
 

Similar to Sql commands

Les09 (using ddl statements to create and manage tables)
Les09 (using ddl statements to create and manage tables)Les09 (using ddl statements to create and manage tables)
Les09 (using ddl statements to create and manage tables)Achmad Solichin
 
Sql practise for beginners
Sql practise for beginnersSql practise for beginners
Sql practise for beginnersISsoft
 
Creating database using sql commands
Creating database using sql commandsCreating database using sql commands
Creating database using sql commandsBelle Wx
 
SQL FILE FROM MOODLEUSE [master]GO Object Databa.pdf
SQL FILE FROM MOODLEUSE [master]GO Object Databa.pdfSQL FILE FROM MOODLEUSE [master]GO Object Databa.pdf
SQL FILE FROM MOODLEUSE [master]GO Object Databa.pdfarrowit1
 
DDL,DML,SQL Functions and Joins
DDL,DML,SQL Functions and JoinsDDL,DML,SQL Functions and Joins
DDL,DML,SQL Functions and JoinsAshwin Dinoriya
 
Using ddl statements to create and manage tables
Using ddl statements to create and manage tablesUsing ddl statements to create and manage tables
Using ddl statements to create and manage tablesSyed Zaid Irshad
 
data constraints,group by
data constraints,group by data constraints,group by
data constraints,group by Visakh V
 
SQL Quick Reference Card
SQL Quick Reference CardSQL Quick Reference Card
SQL Quick Reference CardTechcanvass
 

Similar to Sql commands (20)

Sql
SqlSql
Sql
 
Select To Order By
Select  To  Order BySelect  To  Order By
Select To Order By
 
Les09 (using ddl statements to create and manage tables)
Les09 (using ddl statements to create and manage tables)Les09 (using ddl statements to create and manage tables)
Les09 (using ddl statements to create and manage tables)
 
Les09
Les09Les09
Les09
 
Oraclesql
OraclesqlOraclesql
Oraclesql
 
Sql practise for beginners
Sql practise for beginnersSql practise for beginners
Sql practise for beginners
 
Query
QueryQuery
Query
 
Creating database using sql commands
Creating database using sql commandsCreating database using sql commands
Creating database using sql commands
 
dbms.pdf
dbms.pdfdbms.pdf
dbms.pdf
 
SQL FILE FROM MOODLEUSE [master]GO Object Databa.pdf
SQL FILE FROM MOODLEUSE [master]GO Object Databa.pdfSQL FILE FROM MOODLEUSE [master]GO Object Databa.pdf
SQL FILE FROM MOODLEUSE [master]GO Object Databa.pdf
 
DOODB_LAB.pptx
DOODB_LAB.pptxDOODB_LAB.pptx
DOODB_LAB.pptx
 
DDL,DML,SQL Functions and Joins
DDL,DML,SQL Functions and JoinsDDL,DML,SQL Functions and Joins
DDL,DML,SQL Functions and Joins
 
MY SQL
MY SQLMY SQL
MY SQL
 
Db1 lecture4
Db1 lecture4Db1 lecture4
Db1 lecture4
 
Using ddl statements to create and manage tables
Using ddl statements to create and manage tablesUsing ddl statements to create and manage tables
Using ddl statements to create and manage tables
 
SQL
SQLSQL
SQL
 
Chap 7
Chap 7Chap 7
Chap 7
 
data constraints,group by
data constraints,group by data constraints,group by
data constraints,group by
 
SQL Quick Reference Card
SQL Quick Reference CardSQL Quick Reference Card
SQL Quick Reference Card
 
Sql
SqlSql
Sql
 

More from Christalin Nelson (19)

Packages and Subpackages in Java
Packages and Subpackages in JavaPackages and Subpackages in Java
Packages and Subpackages in Java
 
Bitwise complement operator
Bitwise complement operatorBitwise complement operator
Bitwise complement operator
 
Advanced Data Structures - Vol.2
Advanced Data Structures - Vol.2Advanced Data Structures - Vol.2
Advanced Data Structures - Vol.2
 
Deadlocks
DeadlocksDeadlocks
Deadlocks
 
CPU Scheduling
CPU SchedulingCPU Scheduling
CPU Scheduling
 
Process Synchronization
Process SynchronizationProcess Synchronization
Process Synchronization
 
Process Management
Process ManagementProcess Management
Process Management
 
Applications of Stack
Applications of StackApplications of Stack
Applications of Stack
 
Storage system architecture
Storage system architectureStorage system architecture
Storage system architecture
 
Data Storage and Information Management
Data Storage and Information ManagementData Storage and Information Management
Data Storage and Information Management
 
Application Middleware Overview
Application Middleware OverviewApplication Middleware Overview
Application Middleware Overview
 
Network security
Network securityNetwork security
Network security
 
Directory services
Directory servicesDirectory services
Directory services
 
System overview
System overviewSystem overview
System overview
 
Storage overview
Storage overviewStorage overview
Storage overview
 
Computer Fundamentals-2
Computer Fundamentals-2Computer Fundamentals-2
Computer Fundamentals-2
 
Computer Fundamentals - 1
Computer Fundamentals - 1Computer Fundamentals - 1
Computer Fundamentals - 1
 
Advanced data structures vol. 1
Advanced data structures   vol. 1Advanced data structures   vol. 1
Advanced data structures vol. 1
 
Programming in c++
Programming in c++Programming in c++
Programming in c++
 

Recently uploaded

Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
“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
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
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
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
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
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Recently uploaded (20)

Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
“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...
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
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
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
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
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
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
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 

Sql commands

  • 1. 1. Select 2. Select with Boolean Exp 3. Select with Numeric Exp 4. Select with Date Exp 5. Create DB 6. Drop DB 7. Use DB 8. Create tab 9. Describe tab 10. Drop tab 11. Insert record 12. Update record(s) 13. Delete record(s) 14. Like clause with Select statement 15. Top clause with Select Statement 16. Order By clause with Select Statement 17. Group By clause with Select Statement 18. Distinct clause with Select Statement 19. Default constraint 20. Identity Property 21. Unique constraint 22. Check constraint 23. Alter Table 24. Primary Key constraint 25. Foreign Key constraint 26. Index 27. Views 28. Equi-Join 29. Natural Join 30. Cross Join 1) Select statement SELECT column1, column2, columnN FROM table_name; SQL> SELECT * FROM customers; SQL> SELECT customerID, customername, city FROM CUSTOMERS; SELECT column1, column2, columnN FROM table_name WHERE [condition] //condition- used logical/comparison operators SQL>SELECT * FROM OrderDetails where quantity>80; SELECT column1, column2, columnN FROM table_name WHERE [condition1] AND [condition2]...AND [conditionN]; SQL>SELECT * FROM Orders where shipperID>2 and employeeID=4; //and operator SELECT column1, column2, columnN FROM table_name WHERE [CONDITION|EXPRESSION]; 2) Boolean Expression SELECT column1, column2, columnN FROM table_name WHERE SINGLE VALUE MATCHING EXPRESSION; SQL> SELECT * FROM CUSTOMERS WHERE City = 'Berlin'; 3) Numeric Expression SELECT numerical_expression as OPERATION_NAME [FROM table_name
  • 2. WHERE CONDITION]; SQL> SELECT (15 + 6) AS ADDITION; SQL> SELECT COUNT(*) AS "No of Records" FROM CUSTOMERS; //Built-in fns: avg(), sum() 4) Date Expression SQL> SELECT CURRENT_TIMESTAMP; SQL> SELECT GETDATE(); 5) Create DB CREATE DATABASE DatabaseName; SQL> CREATE DATABASE testDB; SQL> SHOW DATABASES; 6) Drop DB DROP DATABASE DatabaseName; SQL> DROP DATABASE testDB; SQL> SHOW DATABASES; 7) Use DB USE DatabaseName; SQL> SHOW DATABASES; SQL> USE testDB; 8) Create Table CREATE TABLE table_name( column1 datatype, column2 datatype, column3 datatype, ..... columnN datatype, PRIMARY KEY( one or more columns ) ); SQL> CREATE TABLE CUSTOMERS( ID INT NOT NULL, NAME VARCHAR (20) NOT NULL, AGE INT NOT NULL, ADDRESS CHAR (25) , SALARY DECIMAL (18, 2), PRIMARY KEY (ID)
  • 3. ); SQL> create table sample (age int, name varchar(20) default 'Tanya'); SQL> insert into sample (age) values (20); SQL> DESC CUSTOMERS; 9) Describe Table SQL> DESC CUSTOMERS; 10) Drop Table DROP TABLE table_name; SQL> DESC CUSTOMERS; SQL> DROP TABLE CUSTOMERS; SQL> DESC CUSTOMERS; 11) Insert Record (Specific Columns or all Columns in a Record, Populate table using another table) INSERT INTO TABLE_NAME (column1, column2, column3,...columnN) VALUES (value1, value2, value3,...valueN); SQL> INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY) VALUES (6, 'Komal', 22, 'MP', 4500.00 ); INSERT INTO TABLE_NAME VALUES (value1,value2,value3,...valueN); SQL> INSERT INTO CUSTOMERS VALUES (7, 'Muffy', 24, 'Indore', 10000.00 ); INSERT INTO first_table_name [(column1, column2, ... columnN)] SELECT column1, column2, ...columnN FROM second_table_name [WHERE condition]; 12) Update Record(s) UPDATE table_name SET column1 = value1, column2 = value2...., columnN = valueN WHERE [condition]; SQL> UPDATE CUSTOMERS SET ADDRESS = 'Pune' WHERE ID = 6; UPDATE table_name SET column1 = value1, column2 = value2...., columnN = valueN; SQL> UPDATE CUSTOMERS SET ADDRESS = 'Pune', SALARY = 1000.00; 13) Delete Record(s) DELETE FROM table_name WHERE [condition]; SQL> DELETE FROM CUSTOMERS WHERE ID = 6; DELETE FROM table_name;
  • 4. SQL> DELETE FROM CUSTOMERS; 14) Like clause with Select statement Finds any values that start with XXXX SELECT FROM table_name WHERE column LIKE 'XXXX%'; SELECT * FROM Customers where postalcode like '0%'; Finds any values that end with XXXX SELECT FROM table_name WHERE column LIKE '%XXXX'; SELECT * FROM Customers where postalcode like '%3'; Finds any values that have XXXX in any position SELECT FROM table_name WHERE column LIKE '%XXXX%'; SELECT * FROM Products where productname like '%bo%'; Finds any values that have XXXX in certain positions SELECT FROM table_name WHERE column LIKE '_XXXX%'; SELECT * FROM Suppliers where phone like '_1%'; SELECT * FROM Suppliers where phone like '_1%2'; 15) Top clause with Select Statement to fetch few records SELECT TOP number|percent column_name(s) FROM table_name WHERE [condition] SQL> SELECT TOP 3 * FROM CUSTOMERS; SQL> SELECT * FROM CUSTOMERS LIMIT 3; //MySQL SQL> SELECT * FROM CUSTOMERS WHERE ROWNUM <= 3; //Oracle 16) Order By clause with Select Statement to sort SELECT column-list FROM table_name [WHERE condition] [ORDER BY column1, column2, .. columnN] [ASC | DESC]; SQL> SELECT * FROM CUSTOMERS order by country, city; // Ascending order is default SELECT * FROM CUSTOMERS order by country, city DESC; 17) Group By clause with Select Statement to arrange identical data into groups SELECT column1, column2 FROM table_name WHERE [ conditions ] GROUP BY column1, column2 ORDER BY column1, column2 SQL> SELECT * FROM OrderDetails order by ProductID; SQL> SELECT ProductID, SUM(Quantity) FROM OrderDetails GROUP BY ProductID; SQL> SELECT ProductID, SUM(Quantity) FROM OrderDetails GROUP BY ProductID order by Sum(Quantity);
  • 5. 18) Distinct clause with Select Statement to eliminate all the duplicate records and fetching only unique records SELECT DISTINCT column1, column2,.....columnN FROM table_name WHERE [condition] SQL> SELECT * FROM Suppliers order by Country; SQL> SELECT Distinct Country, SupplierName, ContactName, City, Phone FROM Suppliers order by Country; 19) DEFAULT constraint SQL> CREATE TABLE users (NAME char(20), AGE integer, PROFESSION varchar(30) DEFAULT "Student"); SQL>INSERT INTO users (NAME, AGE) VALUES ('ALAN', 36); SQL> CREATE TABLE users (NAME char(20), AGE integer, PROFESSION varchar(30) DEFAULT "Student"); SQL>INSERT INTO users (NAME, AGE) VALUES ('ALAN', 36); SQL> CREATE TABLE Order21 ( ID int NOT NULL, OrderNumber int NOT NULL, OrderDate date DEFAULT GETDATE() ); SQL> INSERT INTO Order21 (ID, OrderNumber) VALUES (20, 201); 20) IDENTITY property OF COLUMN SQL> CREATE TABLE dept (DEPTNO smallint NOT NULL IDENTITY (500, 1), DEPTNAME varchar(36) NOT NULL, DEPTID smallint NOT NULL, LOCATION char(30)); SQL> INSERT INTO dept (DEPTNAME, DEPTID) VALUES ('MECH', 20); SQL> INSERT INTO dept (DEPTNAME, DEPTID, LOCATION) VALUES ('CSE', 10, 'INDIA'); 21) UNIQUE constraint SQL> CREATE TABLE Persons (ID int NOT NULL UNIQUE, LastName varchar(255) NOT NULL, FirstName varchar(255), Age int); SQL> INSERT INTO Persons (ID, LastName, Age) VALUES (100, 'BROWN', 20); SQL> INSERT INTO Persons (ID, LastName, Age) VALUES (100, 'RED', 20); ………………ERROR 22) Check constraint SQL> CREATE TABLE employee (ID integer NOT NULL, NAME varchar(9), DEPT smallint CHECK (DEPT BETWEEN 10 AND 100), JOB char(5) CHECK (JOB IN ('Sales', 'IT', 'Clerk')), HIREDATE DATE, SALARY DECIMAL(7,2), CONSTRAINT YEARSAL CHECK (YEAR(HIREDATE) > 2000 OR SALARY>10000) );
  • 6. SQL> INSERT INTO employee (ID, DEPT, JOB, HIREDATE, SALARY) VALUES (100, 55, 'Sales', 1995, 12000); SQL> INSERT INTO employee (ID, DEPT, JOB, HIREDATE, SALARY) VALUES (100, 55, 'Sales', 1995, 9000); ………………ERROR SQL> INSERT INTO employee (ID, DEPT, JOB, HIREDATE, SALARY) VALUES (100, 200, 'Sales', 1995, 9000); ………………ERROR SQL> INSERT INTO employee (ID, DEPT, JOB, HIREDATE, SALARY) VALUES (100, 200, ‘Sale', 1995, 9000); ………………ERROR 23) Alter table SQL> CREATE TABLE employee (ID integer NOT NULL, NAME varchar(9), DEPT smallint CHECK (DEPT BETWEEN 10 AND 100), JOB char(5) CHECK (JOB IN ('Sales', 'IT', 'Clerk')), HIREDATE DATE, SALARY DECIMAL(7,2), CONSTRAINT YEARSAL CHECK (YEAR(HIREDATE) > 2000 OR SALARY>10000) ); SQL> ALTER TABLE employee DROP COLUMN NAME; SQL> ALTER TABLE employee ADD COLUMN NAME varchar(9); 24) Primary Key Constraint SQL> CREATE TABLE personnel ( ID int NOT NULL PRIMARY KEY, LastName varchar(255) NOT NULL, FirstName varchar(255), Age int ); SQL> CREATE TABLE personnel1 ( ID int NOT NULL, LastName varchar(255) NOT NULL, FirstName varchar(255), Age int, CONSTRAINT PK_Person PRIMARY KEY (ID,LastName) ); 25) Foreign Key Constraint SQL> CREATE TABLE personnel ( ID int NOT NULL PRIMARY KEY, LastName varchar(255) NOT NULL, FirstName varchar(255), Age int ); SQL> CREATE TABLE Order ( OrderID int NOT NULL PRIMARY KEY, OrderNumber int NOT NULL, ID int FOREIGN KEY REFERENCES personnel(ID) );
  • 7. 26) Index Constraint SQL> CREATE INDEX index_id ON Order21 (ID); 27) Views SQL> CREATE TABLE personnel ( ID int NOT NULL PRIMARY KEY, LastName varchar(255) NOT NULL, FirstName varchar(255), Age int ); SQL> INSERT INTO personnel (ID, LastName, FirstName, Age) VALUES (10, 'BROWN', 'TIM', 28); SQL> CREATE VIEW myview1 AS SELECT ID, FirstName FROM personnel; SQL> SELECT * FROM myview1; 28)Equi-Join Select * FROM student, enrollment WHERE student.enrollment_no = enrollment.enrollment_no; (or) Select * FROM student INNER JOIN enrollment ON student.enrollment_no = enrollment.enrollment_no; 29) Natural Join SELECT * FROM student NATURAL JOIN enrollment; 30) Cross Join SELECT * FROM student, enrollment;