SlideShare a Scribd company logo
1 of 30
SQL Assessment Commands
Query Command Statement Examples
• SELECT
• INSERT
• AND
• FROM
• IF
• WHERE
• AS
• OR
• DELETE
• DROP
• ALTER
Datatype Examples
• CHAR
• VARCHAR
• INT
• MEDIUMINT
• TEXT
• BLOB
• MEDIUMBLOB
SELECT Command Statement
• The SELECT statement is used to select data from a database
Examples:
The following SQL statement selects the "CustomerName" and "City" columns from
the "Customers" table:
SELECT CustomerName, City FROM Customers;
The following SQL statement selects all the columns from the "Customers" table:
SELECT * FROM Customers;
WHERE Command Statement
• The WHERE statement is used to filter records. The WHERE clause is used to extract
records that fulfil a specified criteria only.
Examples:
The following SQL statement selects all the customers from the country "Mexico", in the
"Customers" table:
SELECT * FROM Customers
WHERE Country='Mexico’;
However, numeric fields should not be enclosed in quotes:
SELECT * FROM Customers
WHERE CustomerID=1;
WHERE Clause Operators
Operator Description
= Equal
<> Not Equal
> Greater than
< Less than
>= Greater than or equal
<= Less than or equal
BETWEEN Between an inclusive range
LIKE Search for a pattern
IN To specify multiple possible values for a column
AND Command Statement
• The AND and OR operators are used to filter records based on more than
one condition:
• The AND operator displays a record if all the conditions separated by AND is TRUE:
Example:
The following SQL statement selects all fields from "Customers" where
country is "Germany" AND city is "Berlin":
SELECT * FROM Customers
WHERE Country='Germany' AND City='Berlin';
OR Command Statement
• The AND and OR operators are used to filter records based on more than
one condition:
• The OR operator displays a record if any of the conditions separated by OR is TRUE.
Examples:
The following SQL statement selects all fields from "Customers" where city is
"Berlin" OR "München":
SELECT * FROM Customers
WHERE City='Berlin' OR City='München';
NOT Command Statement
• The NOT operator displays a record if the condition(s) is NOT TRUE:
Examples:
The following SQL statement selects all fields from "Customers" where
country is NOT "Germany":
SELECT * FROM Customers
WHERE NOT Country='Germany';
Combining AND, OR and NOT operators
• You can also combine the AND, OR and NOT operators:
Examples:
The following SQL statement selects all fields from "Customers" where country is
"Germany" AND city must be "Berlin" OR "München":
SELECT * FROM Customers
WHERE Country='Germany' AND (City='Berlin' OR City='München’);
The following SQL statement selects all fields from "Customers" where country is
NOT "Germany" and NOT "USA":
SELECT * FROM Customers
WHERE NOT Country='Germany' AND NOT Country='USA';
INSERT INTO Command Statement
• The INSERT INTO statement is used to insert new records in a table:
Syntax:
INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);
Examples:
The following SQL statement inserts a new record in the "Customers" table:
INSERT INTO Customers (CustomerName, ContactName, Address, City, PostalCode,
Country)
VALUES ('Cardinal', 'Tom B. Erichsen', 'Skagen 21', 'Stavanger', '4006', 'Norway');
INSERT INTO only specified table columns
• It is also possible to only insert data in specific columns.
Examples:
The following SQL statement will insert a new record, but only insert
data in the "CustomerName", "City", and "Country" columns:
INSERT INTO Customers (CustomerName, City, Country)
VALUES ('Cardinal', 'Stavanger', 'Norway’);
SQL NULL Values
• A field with a NULL value is a field with no value.
Note:
A NULL value is different from a zero value or a field that contains
spaces. A field with a NULL value is one that has been left blank during
record creation.
UPDATE Command Statement
• The UPDATE statement is used to modify the existing records in a table.
Example:
The following SQL statement updates the first customer (CustomerID = 1)
with a new contact person and a new city (Alfred and Frankfurt are new
values):
UPDATE Customers
SET ContactName = 'Alfred Schmidt', City= 'Frankfurt'
WHERE CustomerID = 1;
UPDATE Multiple Records
• It is the WHERE clause that determines how many records that will be
updated:
Example:
The following SQL statement will update the contactname to "Juan" for all
records where country is "Mexico":
UPDATE Customers
SET ContactName='Juan'
WHERE Country='Mexico’;
Note: Missing out the WHERE statement will alter every value under SET
DELETE Command Statement
• The DELETE statement is used to delete existing records in a table.
Example:
The following SQL statement deletes the customer “John Smith" from the
"Customers" table:
DELETE FROM Customers
WHERE CustomerName=‘John Smith’;
Note: To delete all from a table, use:
DELETE * FROM table_name;
CREATE DATABASE Command Statement
• The CREATE DATABASE statement is used to create a new SQL
database:
Syntax:
CREATE DATABASE databasename;
Example:
CREATE DATABASE testDB;
DROP DATABASE Command Statement
• The DROP DATABASE statement is used to drop an existing SQL database:
Syntax:
DROP DATABASE databasename;
Example:
DROP DATABASE testDB;
CREATE TABLE Command Statement
• The CREATE TABLE statement is used to create a new table in a
database:
Syntax:
CREATE TABLE table_name (
column1 datatype,
column2 datatype,
column3 datatype,
....
);
CREATE TABLE continued…
Example:
CREATE TABLE testtable (
PersonID int,
LastName varchar(255),
FirstName varchar(255),
Address varchar(255),
City varchar(255)
);
DROP TABLE Command Statement
• The DROP TABLE statement is used to drop an existing table in a
database.
Syntax:
DROP TABLE table_name;
Example:
DROP TABLE testtable;
TRUNCATE TABLE Command Statement
• The TRUNCATE TABLE statement is used to delete the data inside a
table, but not the table itself.
Syntax:
TRUNCATE TABLE table_name;
Example:
TRUNCATE TABLE testtable;
ALTER TABLE Command Statement
• The ALTER TABLE statement is used to add, delete, or modify columns
in an existing table.
• The ALTER TABLE statement is also used to add and drop various
constraints on an existing table.
Syntax:
To add a column in a table, use the following syntax:
ALTER TABLE table_name
ADD column_name datatype;
ALTER TABLE continued…
Syntax:
To delete a column in a table, use the following syntax:
ALTER TABLE table_name
DROP COLUMN column_name;
Examples:
ALTER TABLE testtable
ADD DateOfBirth date;
ALTER TABLE continued…
Examples:
The following deletes the column named "DateOfBirth" in the “testtable"
table:
ALTER TABLE Persons
DROP COLUMN DateOfBirth;
The following changes the data type of the column named "DateOfBirth" in
the “testtable" table (date to year):
ALTER TABLE Persons
ALTER COLUMN DateOfBirth year;
SQL Constraints Examples
• SQL constraints are used to specify rules for the data in a table:
• The following constraints are commonly used in SQL:
• NOT NULL - Ensures that a column cannot have a NULL value
• UNIQUE - Ensures that all values in a column are different
• PRIMARY KEY - A combination of a NOT NULL and UNIQUE. Uniquely
identifies each row in a table
• FOREIGN KEY - Uniquely identifies a row/record in another table
• CHECK - Ensures that all values in a column satisfies a specific condition
• DEFAULT - Sets a default value for a column when no value is specified
• INDEX - Used to create and retrieve data from the database very quickly
PRIMARY KEY Constraint
• The PRIMARY KEY constraint uniquely identifies each record in a database
table.
• Primary keys must contain UNIQUE values, and cannot contain NULL
values.
PRIMARY KEY on CREATE TABLE:
CREATE TABLE testtable (
ID int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Age int,
PRIMARY KEY (ID)
);
PRIMARY KEY continued…
PRIMARY KEY on ALTER TABLE:
ALTER TABLE testtable
ADD PRIMARY KEY (ID);
DROP a PRIMARY KEY:
ALTER TABLE testtable
DROP PRIMARY KEY;
FOREIGN KEY Constraint
• A FOREIGN KEY is a key used to link two tables together.
• A FOREIGN KEY is a field (or multiple) in one table that refers to the
PRIMARY KEY in another table:
FOREIGN KEY on CREATE TABLE:
CREATE TABLE Orders (
OrderID int NOT NULL,
OrderNumber int NOT NULL,
PersonID int,
PRIMARY KEY (OrderID),
FOREIGN KEY (PersonID) REFERENCES testtable(PersonID)
);
FOREIGN KEY continued…
FOREIGN KEY on ALTER TABLE:
ALTER TABLE Orders
ADD FOREIGN KEY (PersonID) REFERENCES testtable(PersonID);
DROP a FOREIGN KEY:
ALTER TABLE Orders
DROP FOREIGN KEY FK_PersonOrder;

More Related Content

What's hot

Structure query language (sql)
Structure query language (sql)Structure query language (sql)
Structure query language (sql)Nalina Kumari
 
SQL Fundamentals
SQL FundamentalsSQL Fundamentals
SQL FundamentalsBrian Foote
 
15 wordprocessing ml subject - fields and hyperlinks
15   wordprocessing ml subject - fields and hyperlinks15   wordprocessing ml subject - fields and hyperlinks
15 wordprocessing ml subject - fields and hyperlinksShawn Villaron
 
Introduction to SQL
Introduction to SQLIntroduction to SQL
Introduction to SQLMahir Haque
 
Sql server ___________session 3(sql 2008)
Sql server  ___________session 3(sql 2008)Sql server  ___________session 3(sql 2008)
Sql server ___________session 3(sql 2008)Ehtisham Ali
 
Database Management Essentials: Module 4 Basic Query Formulation with SQL
Database Management Essentials: Module 4 Basic Query Formulation with SQLDatabase Management Essentials: Module 4 Basic Query Formulation with SQL
Database Management Essentials: Module 4 Basic Query Formulation with SQLDonggun Kim
 
DDL,DML,SQL Functions and Joins
DDL,DML,SQL Functions and JoinsDDL,DML,SQL Functions and Joins
DDL,DML,SQL Functions and JoinsAshwin Dinoriya
 
Sql coding-standard-sqlserver
Sql coding-standard-sqlserverSql coding-standard-sqlserver
Sql coding-standard-sqlserverlochaaaa
 
SQL Server Learning Drive
SQL Server Learning Drive SQL Server Learning Drive
SQL Server Learning Drive TechandMate
 
Database Systems - SQL - DDL Statements (Chapter 3/2)
Database Systems - SQL - DDL Statements (Chapter 3/2)Database Systems - SQL - DDL Statements (Chapter 3/2)
Database Systems - SQL - DDL Statements (Chapter 3/2)Vidyasagar Mundroy
 
Using Access to Create Reports from Voyager (Microsoft Access with the Voyage...
Using Access to Create Reports from Voyager (Microsoft Access with the Voyage...Using Access to Create Reports from Voyager (Microsoft Access with the Voyage...
Using Access to Create Reports from Voyager (Microsoft Access with the Voyage...Alan Manifold
 

What's hot (20)

Structure query language (sql)
Structure query language (sql)Structure query language (sql)
Structure query language (sql)
 
SQL
SQLSQL
SQL
 
Sql 2006
Sql 2006Sql 2006
Sql 2006
 
SQL Fundamentals
SQL FundamentalsSQL Fundamentals
SQL Fundamentals
 
15 wordprocessing ml subject - fields and hyperlinks
15   wordprocessing ml subject - fields and hyperlinks15   wordprocessing ml subject - fields and hyperlinks
15 wordprocessing ml subject - fields and hyperlinks
 
Introduction to SQL
Introduction to SQLIntroduction to SQL
Introduction to SQL
 
MY SQL
MY SQLMY SQL
MY SQL
 
Sql server ___________session 3(sql 2008)
Sql server  ___________session 3(sql 2008)Sql server  ___________session 3(sql 2008)
Sql server ___________session 3(sql 2008)
 
Access 04
Access 04Access 04
Access 04
 
Database Management Essentials: Module 4 Basic Query Formulation with SQL
Database Management Essentials: Module 4 Basic Query Formulation with SQLDatabase Management Essentials: Module 4 Basic Query Formulation with SQL
Database Management Essentials: Module 4 Basic Query Formulation with SQL
 
DDL,DML,SQL Functions and Joins
DDL,DML,SQL Functions and JoinsDDL,DML,SQL Functions and Joins
DDL,DML,SQL Functions and Joins
 
Sql functions
Sql functionsSql functions
Sql functions
 
SQL report
SQL reportSQL report
SQL report
 
BIS05 Introduction to SQL
BIS05 Introduction to SQLBIS05 Introduction to SQL
BIS05 Introduction to SQL
 
SQL Inteoduction to SQL manipulating of data
SQL Inteoduction to SQL manipulating of data   SQL Inteoduction to SQL manipulating of data
SQL Inteoduction to SQL manipulating of data
 
Sql coding-standard-sqlserver
Sql coding-standard-sqlserverSql coding-standard-sqlserver
Sql coding-standard-sqlserver
 
SQL Server Learning Drive
SQL Server Learning Drive SQL Server Learning Drive
SQL Server Learning Drive
 
Database Systems - SQL - DDL Statements (Chapter 3/2)
Database Systems - SQL - DDL Statements (Chapter 3/2)Database Systems - SQL - DDL Statements (Chapter 3/2)
Database Systems - SQL - DDL Statements (Chapter 3/2)
 
Oraclesql
OraclesqlOraclesql
Oraclesql
 
Using Access to Create Reports from Voyager (Microsoft Access with the Voyage...
Using Access to Create Reports from Voyager (Microsoft Access with the Voyage...Using Access to Create Reports from Voyager (Microsoft Access with the Voyage...
Using Access to Create Reports from Voyager (Microsoft Access with the Voyage...
 

Similar to SQL Assessment Command Statements

SQL Beginners anishurrehman.cloud.pdf
SQL Beginners anishurrehman.cloud.pdfSQL Beginners anishurrehman.cloud.pdf
SQL Beginners anishurrehman.cloud.pdfAnishurRehman1
 
ADV Powepoint 2 Lec.pptx
ADV Powepoint 2 Lec.pptxADV Powepoint 2 Lec.pptx
ADV Powepoint 2 Lec.pptxArjayBalberan1
 
DBMS information in detail || Dbms (lab) ppt
DBMS information in detail || Dbms (lab) pptDBMS information in detail || Dbms (lab) ppt
DBMS information in detail || Dbms (lab) pptgourav kottawar
 
SQL.pptx for the begineers and good know
SQL.pptx for the begineers and good knowSQL.pptx for the begineers and good know
SQL.pptx for the begineers and good knowPavithSingh
 
Presentation slides of Sequence Query Language (SQL)
Presentation slides of Sequence Query Language (SQL)Presentation slides of Sequence Query Language (SQL)
Presentation slides of Sequence Query Language (SQL)Punjab University
 
Tk2323 lecture 7 sql
Tk2323 lecture 7   sql Tk2323 lecture 7   sql
Tk2323 lecture 7 sql MengChun Lam
 
Creating database using sql commands
Creating database using sql commandsCreating database using sql commands
Creating database using sql commandsBelle Wx
 
Aggregate functions in SQL.pptx
Aggregate functions in SQL.pptxAggregate functions in SQL.pptx
Aggregate functions in SQL.pptxSherinRappai1
 
Aggregate functions in SQL.pptx
Aggregate functions in SQL.pptxAggregate functions in SQL.pptx
Aggregate functions in SQL.pptxSherinRappai
 
Data Base Management System Lecture 10.pdf
Data Base Management System Lecture 10.pdfData Base Management System Lecture 10.pdf
Data Base Management System Lecture 10.pdfhowto4ucontact
 
Sql ch 12 - creating database
Sql ch 12 - creating databaseSql ch 12 - creating database
Sql ch 12 - creating databaseMukesh Tekwani
 

Similar to SQL Assessment Command Statements (20)

SQL Beginners anishurrehman.cloud.pdf
SQL Beginners anishurrehman.cloud.pdfSQL Beginners anishurrehman.cloud.pdf
SQL Beginners anishurrehman.cloud.pdf
 
ADV Powepoint 2 Lec.pptx
ADV Powepoint 2 Lec.pptxADV Powepoint 2 Lec.pptx
ADV Powepoint 2 Lec.pptx
 
DBMS information in detail || Dbms (lab) ppt
DBMS information in detail || Dbms (lab) pptDBMS information in detail || Dbms (lab) ppt
DBMS information in detail || Dbms (lab) ppt
 
SQL.pptx for the begineers and good know
SQL.pptx for the begineers and good knowSQL.pptx for the begineers and good know
SQL.pptx for the begineers and good know
 
Presentation slides of Sequence Query Language (SQL)
Presentation slides of Sequence Query Language (SQL)Presentation slides of Sequence Query Language (SQL)
Presentation slides of Sequence Query Language (SQL)
 
Tk2323 lecture 7 sql
Tk2323 lecture 7   sql Tk2323 lecture 7   sql
Tk2323 lecture 7 sql
 
MS SQL Server
MS SQL ServerMS SQL Server
MS SQL Server
 
Creating database using sql commands
Creating database using sql commandsCreating database using sql commands
Creating database using sql commands
 
Aggregate functions in SQL.pptx
Aggregate functions in SQL.pptxAggregate functions in SQL.pptx
Aggregate functions in SQL.pptx
 
Aggregate functions in SQL.pptx
Aggregate functions in SQL.pptxAggregate functions in SQL.pptx
Aggregate functions in SQL.pptx
 
Ms sql-server
Ms sql-serverMs sql-server
Ms sql-server
 
Data Base Management System Lecture 10.pdf
Data Base Management System Lecture 10.pdfData Base Management System Lecture 10.pdf
Data Base Management System Lecture 10.pdf
 
2..basic queries.pptx
2..basic queries.pptx2..basic queries.pptx
2..basic queries.pptx
 
UNIT2.ppt
UNIT2.pptUNIT2.ppt
UNIT2.ppt
 
Sql ch 12 - creating database
Sql ch 12 - creating databaseSql ch 12 - creating database
Sql ch 12 - creating database
 
Sql
SqlSql
Sql
 
Rdbms day3
Rdbms day3Rdbms day3
Rdbms day3
 
Introduction to sql_02
Introduction to sql_02Introduction to sql_02
Introduction to sql_02
 
2.2 sql commands
2.2 sql commands2.2 sql commands
2.2 sql commands
 
Unit - II.pptx
Unit - II.pptxUnit - II.pptx
Unit - II.pptx
 

More from Shaun Wilson

Troubleshooting Computing Problems
Troubleshooting Computing ProblemsTroubleshooting Computing Problems
Troubleshooting Computing ProblemsShaun Wilson
 
Professionalism and Ethics
Professionalism and EthicsProfessionalism and Ethics
Professionalism and EthicsShaun Wilson
 
Software Development (Mobile Technology)
Software Development (Mobile Technology)Software Development (Mobile Technology)
Software Development (Mobile Technology)Shaun Wilson
 
Computer Systems Fundamentals
Computer Systems FundamentalsComputer Systems Fundamentals
Computer Systems FundamentalsShaun Wilson
 
Introduction to Project Management Assessment Notes
Introduction to Project Management Assessment NotesIntroduction to Project Management Assessment Notes
Introduction to Project Management Assessment NotesShaun Wilson
 
The Rise and Fall of the Roman Empire
The Rise and Fall of the Roman EmpireThe Rise and Fall of the Roman Empire
The Rise and Fall of the Roman EmpireShaun Wilson
 
National 5 Graphic Communication
National 5 Graphic CommunicationNational 5 Graphic Communication
National 5 Graphic CommunicationShaun Wilson
 
Vector multiplication dot product
Vector multiplication   dot productVector multiplication   dot product
Vector multiplication dot productShaun Wilson
 
Dot product calc angle to finish!
Dot product calc angle to finish!Dot product calc angle to finish!
Dot product calc angle to finish!Shaun Wilson
 
Vector bits and pieces
Vector bits and piecesVector bits and pieces
Vector bits and piecesShaun Wilson
 
Parallel + collinear vectors
Parallel + collinear vectorsParallel + collinear vectors
Parallel + collinear vectorsShaun Wilson
 
Position and 3 d vectors amended
Position and 3 d vectors amendedPosition and 3 d vectors amended
Position and 3 d vectors amendedShaun Wilson
 
Solving trig equations higher
Solving trig equations higherSolving trig equations higher
Solving trig equations higherShaun Wilson
 
Solving trig equations + double angle formulae
Solving trig equations  + double angle formulaeSolving trig equations  + double angle formulae
Solving trig equations + double angle formulaeShaun Wilson
 
Solving exponential equations
Solving exponential equationsSolving exponential equations
Solving exponential equationsShaun Wilson
 

More from Shaun Wilson (20)

Troubleshooting Computing Problems
Troubleshooting Computing ProblemsTroubleshooting Computing Problems
Troubleshooting Computing Problems
 
Professionalism and Ethics
Professionalism and EthicsProfessionalism and Ethics
Professionalism and Ethics
 
Software Development (Mobile Technology)
Software Development (Mobile Technology)Software Development (Mobile Technology)
Software Development (Mobile Technology)
 
Computer Systems Fundamentals
Computer Systems FundamentalsComputer Systems Fundamentals
Computer Systems Fundamentals
 
Introduction to Project Management Assessment Notes
Introduction to Project Management Assessment NotesIntroduction to Project Management Assessment Notes
Introduction to Project Management Assessment Notes
 
The Rise and Fall of the Roman Empire
The Rise and Fall of the Roman EmpireThe Rise and Fall of the Roman Empire
The Rise and Fall of the Roman Empire
 
National 5 Graphic Communication
National 5 Graphic CommunicationNational 5 Graphic Communication
National 5 Graphic Communication
 
Vector journeys!
Vector journeys!Vector journeys!
Vector journeys!
 
Vector multiplication dot product
Vector multiplication   dot productVector multiplication   dot product
Vector multiplication dot product
 
Dot product calc angle to finish!
Dot product calc angle to finish!Dot product calc angle to finish!
Dot product calc angle to finish!
 
Unit vectors 14
Unit vectors 14Unit vectors 14
Unit vectors 14
 
Vector bits and pieces
Vector bits and piecesVector bits and pieces
Vector bits and pieces
 
Vectors intro
Vectors introVectors intro
Vectors intro
 
Ratios
RatiosRatios
Ratios
 
Parallel + collinear vectors
Parallel + collinear vectorsParallel + collinear vectors
Parallel + collinear vectors
 
Position and 3 d vectors amended
Position and 3 d vectors amendedPosition and 3 d vectors amended
Position and 3 d vectors amended
 
Solving trig equations higher
Solving trig equations higherSolving trig equations higher
Solving trig equations higher
 
Solving trig equations + double angle formulae
Solving trig equations  + double angle formulaeSolving trig equations  + double angle formulae
Solving trig equations + double angle formulae
 
Solving exponential equations
Solving exponential equationsSolving exponential equations
Solving exponential equations
 
Logarithms intro
Logarithms introLogarithms intro
Logarithms intro
 

Recently uploaded

HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)cama23
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxMaryGraceBautista27
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 

Recently uploaded (20)

HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptx
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 

SQL Assessment Command Statements

  • 2. Query Command Statement Examples • SELECT • INSERT • AND • FROM • IF • WHERE • AS • OR • DELETE • DROP • ALTER
  • 3. Datatype Examples • CHAR • VARCHAR • INT • MEDIUMINT • TEXT • BLOB • MEDIUMBLOB
  • 4. SELECT Command Statement • The SELECT statement is used to select data from a database Examples: The following SQL statement selects the "CustomerName" and "City" columns from the "Customers" table: SELECT CustomerName, City FROM Customers; The following SQL statement selects all the columns from the "Customers" table: SELECT * FROM Customers;
  • 5. WHERE Command Statement • The WHERE statement is used to filter records. The WHERE clause is used to extract records that fulfil a specified criteria only. Examples: The following SQL statement selects all the customers from the country "Mexico", in the "Customers" table: SELECT * FROM Customers WHERE Country='Mexico’; However, numeric fields should not be enclosed in quotes: SELECT * FROM Customers WHERE CustomerID=1;
  • 6. WHERE Clause Operators Operator Description = Equal <> Not Equal > Greater than < Less than >= Greater than or equal <= Less than or equal BETWEEN Between an inclusive range LIKE Search for a pattern IN To specify multiple possible values for a column
  • 7. AND Command Statement • The AND and OR operators are used to filter records based on more than one condition: • The AND operator displays a record if all the conditions separated by AND is TRUE: Example: The following SQL statement selects all fields from "Customers" where country is "Germany" AND city is "Berlin": SELECT * FROM Customers WHERE Country='Germany' AND City='Berlin';
  • 8. OR Command Statement • The AND and OR operators are used to filter records based on more than one condition: • The OR operator displays a record if any of the conditions separated by OR is TRUE. Examples: The following SQL statement selects all fields from "Customers" where city is "Berlin" OR "München": SELECT * FROM Customers WHERE City='Berlin' OR City='München';
  • 9. NOT Command Statement • The NOT operator displays a record if the condition(s) is NOT TRUE: Examples: The following SQL statement selects all fields from "Customers" where country is NOT "Germany": SELECT * FROM Customers WHERE NOT Country='Germany';
  • 10. Combining AND, OR and NOT operators • You can also combine the AND, OR and NOT operators: Examples: The following SQL statement selects all fields from "Customers" where country is "Germany" AND city must be "Berlin" OR "München": SELECT * FROM Customers WHERE Country='Germany' AND (City='Berlin' OR City='München’); The following SQL statement selects all fields from "Customers" where country is NOT "Germany" and NOT "USA": SELECT * FROM Customers WHERE NOT Country='Germany' AND NOT Country='USA';
  • 11. INSERT INTO Command Statement • The INSERT INTO statement is used to insert new records in a table: Syntax: INSERT INTO table_name (column1, column2, column3, ...) VALUES (value1, value2, value3, ...); Examples: The following SQL statement inserts a new record in the "Customers" table: INSERT INTO Customers (CustomerName, ContactName, Address, City, PostalCode, Country) VALUES ('Cardinal', 'Tom B. Erichsen', 'Skagen 21', 'Stavanger', '4006', 'Norway');
  • 12. INSERT INTO only specified table columns • It is also possible to only insert data in specific columns. Examples: The following SQL statement will insert a new record, but only insert data in the "CustomerName", "City", and "Country" columns: INSERT INTO Customers (CustomerName, City, Country) VALUES ('Cardinal', 'Stavanger', 'Norway’);
  • 13. SQL NULL Values • A field with a NULL value is a field with no value. Note: A NULL value is different from a zero value or a field that contains spaces. A field with a NULL value is one that has been left blank during record creation.
  • 14. UPDATE Command Statement • The UPDATE statement is used to modify the existing records in a table. Example: The following SQL statement updates the first customer (CustomerID = 1) with a new contact person and a new city (Alfred and Frankfurt are new values): UPDATE Customers SET ContactName = 'Alfred Schmidt', City= 'Frankfurt' WHERE CustomerID = 1;
  • 15. UPDATE Multiple Records • It is the WHERE clause that determines how many records that will be updated: Example: The following SQL statement will update the contactname to "Juan" for all records where country is "Mexico": UPDATE Customers SET ContactName='Juan' WHERE Country='Mexico’; Note: Missing out the WHERE statement will alter every value under SET
  • 16. DELETE Command Statement • The DELETE statement is used to delete existing records in a table. Example: The following SQL statement deletes the customer “John Smith" from the "Customers" table: DELETE FROM Customers WHERE CustomerName=‘John Smith’; Note: To delete all from a table, use: DELETE * FROM table_name;
  • 17. CREATE DATABASE Command Statement • The CREATE DATABASE statement is used to create a new SQL database: Syntax: CREATE DATABASE databasename; Example: CREATE DATABASE testDB;
  • 18. DROP DATABASE Command Statement • The DROP DATABASE statement is used to drop an existing SQL database: Syntax: DROP DATABASE databasename; Example: DROP DATABASE testDB;
  • 19. CREATE TABLE Command Statement • The CREATE TABLE statement is used to create a new table in a database: Syntax: CREATE TABLE table_name ( column1 datatype, column2 datatype, column3 datatype, .... );
  • 20. CREATE TABLE continued… Example: CREATE TABLE testtable ( PersonID int, LastName varchar(255), FirstName varchar(255), Address varchar(255), City varchar(255) );
  • 21. DROP TABLE Command Statement • The DROP TABLE statement is used to drop an existing table in a database. Syntax: DROP TABLE table_name; Example: DROP TABLE testtable;
  • 22. TRUNCATE TABLE Command Statement • The TRUNCATE TABLE statement is used to delete the data inside a table, but not the table itself. Syntax: TRUNCATE TABLE table_name; Example: TRUNCATE TABLE testtable;
  • 23. ALTER TABLE Command Statement • The ALTER TABLE statement is used to add, delete, or modify columns in an existing table. • The ALTER TABLE statement is also used to add and drop various constraints on an existing table. Syntax: To add a column in a table, use the following syntax: ALTER TABLE table_name ADD column_name datatype;
  • 24. ALTER TABLE continued… Syntax: To delete a column in a table, use the following syntax: ALTER TABLE table_name DROP COLUMN column_name; Examples: ALTER TABLE testtable ADD DateOfBirth date;
  • 25. ALTER TABLE continued… Examples: The following deletes the column named "DateOfBirth" in the “testtable" table: ALTER TABLE Persons DROP COLUMN DateOfBirth; The following changes the data type of the column named "DateOfBirth" in the “testtable" table (date to year): ALTER TABLE Persons ALTER COLUMN DateOfBirth year;
  • 26. SQL Constraints Examples • SQL constraints are used to specify rules for the data in a table: • The following constraints are commonly used in SQL: • NOT NULL - Ensures that a column cannot have a NULL value • UNIQUE - Ensures that all values in a column are different • PRIMARY KEY - A combination of a NOT NULL and UNIQUE. Uniquely identifies each row in a table • FOREIGN KEY - Uniquely identifies a row/record in another table • CHECK - Ensures that all values in a column satisfies a specific condition • DEFAULT - Sets a default value for a column when no value is specified • INDEX - Used to create and retrieve data from the database very quickly
  • 27. PRIMARY KEY Constraint • The PRIMARY KEY constraint uniquely identifies each record in a database table. • Primary keys must contain UNIQUE values, and cannot contain NULL values. PRIMARY KEY on CREATE TABLE: CREATE TABLE testtable ( ID int NOT NULL, LastName varchar(255) NOT NULL, FirstName varchar(255), Age int, PRIMARY KEY (ID) );
  • 28. PRIMARY KEY continued… PRIMARY KEY on ALTER TABLE: ALTER TABLE testtable ADD PRIMARY KEY (ID); DROP a PRIMARY KEY: ALTER TABLE testtable DROP PRIMARY KEY;
  • 29. FOREIGN KEY Constraint • A FOREIGN KEY is a key used to link two tables together. • A FOREIGN KEY is a field (or multiple) in one table that refers to the PRIMARY KEY in another table: FOREIGN KEY on CREATE TABLE: CREATE TABLE Orders ( OrderID int NOT NULL, OrderNumber int NOT NULL, PersonID int, PRIMARY KEY (OrderID), FOREIGN KEY (PersonID) REFERENCES testtable(PersonID) );
  • 30. FOREIGN KEY continued… FOREIGN KEY on ALTER TABLE: ALTER TABLE Orders ADD FOREIGN KEY (PersonID) REFERENCES testtable(PersonID); DROP a FOREIGN KEY: ALTER TABLE Orders DROP FOREIGN KEY FK_PersonOrder;