SQL 3
SQL 3
Introduction to Querying.
DDL/DQL/DML/DCL/TCL
Zlata Chernysh
Junior Software Engineer
Tetiana Lampiha
Software Engineer
CONFIDENTIAL | © 2021 EPAM Systems, Inc.
Recommendations
1 M U T E YO U R M I C
2 R A I S E H A N D A S K Q U E ST IO NS
3 D U R AT I O N : 3 H O U R S
5 Q & A A FT E R E A C H MO D ULE
6 T E A M S Q U E S TIO N S C H A NN EL
S of tw are Engineer
1 D AT A B A S E . D B M S . R E L AT I O N A L M O D E L
3 D AT A D E F I N I T I O N L A N G U A G E ( D D L )
4 D AT A M A N I P U L AT I O N L A N G U A G E ( D M L )
5 S E L E C T S T AT E M E N T ( D Q L )
6 ALIASES
Database
A relational database (RDB) is a collective set of multiple data sets organized by tables, records and columns. RDBs establish a well-defined
relationship between database tables. Tables are uniquely identified by their names. They communicate and share information, which facilitates
data searchability, organization and reporting.
RDBs use Structured Query Language (SQL)
Briefly, the features of relational databases:
• Data is stored in tables consisting of columns ("attributes") and rows ("records", "tuples").
• There is exactly one value at the intersection of each column and row.
• Each column has a name, and all values in one column are of the same type.
• Database queries return results in the form of tables, which can also act as a query object.
• Rows in a relational database are unordered: the ordering is performed at the moment of generating a response to a query.
• The generally accepted language standard for working with relational databases is the SQL language.
A D V A N TA G E S D I S A D V A N TA G E S
• simplicity and accessibility for user understanding. Only "table“ is • subject area not always can be represented in the form of "tables";
used as an information structure;
• as a result of logical design there is a set of "tables". This leads to
• strict design rules are based on the mathematical theory; difficulties in understanding the data structure;
• complete independence of data. When the relational database is • The database takes up a relatively large amount of external
changed, appropriate changes in the applications are minimal. memory;
• relatively low speed of data access.
The Relational Model (RM) for DBMS is an approach to work with data based on the relation algebra (tuples, sets, relations, a ttributes).
• Tables. In the Relational model the relations are saved in the table format. A table consists of rows and columns. Rows represent records and
columns represent attributes.
• Tuple – a single row of a table, which contains a single record.
• Attribute - each column in a Table. Attributes are the properties which define a relation.
• Attribute domain. Every attribute has some pre-defined value and scope which is known as attribute domain
• Relation Schema - A relation schema represents the name of the relation with its attributes.
• Degree - total number of attributes in the relation.
• Cardinality - total number of rows present in the table.
• Relation instance – Relation instance is a finite set of tuples in the relation. Relation instances never have duplicate tuples.
• Databases using relational model are called Relational Databases. They are managed by Relational DBMSs => RDBMSs.
• RDBMS stands for Relational Database Management System.
• RDBMS is the basis for SQL, and for all modern database systems such as MS SQL Server, IBM DB2, Oracle, MySQL etc.
• The data in RDBMS is stored in database objects called tables. A table is a collection of related data entries and it consist s of columns and rows.
• Every table is broken up into smaller entities called fields. A field is a column in a table that is designed to maintain specific information about
every record in the table.
• A record, also called a row, is each individual entry that exists in a table. A record is a horizontal entity in a table.
• A column is a vertical entity in a table that contains all information associated with a specific field in a table.
• Document model: These NoSQL databases replace the familiar rows and columns structure with a document storage model. Each document is
structured, frequently using the JavaScript Object Notation (JSON) model. The document data model is associated with object -oriented
programming where each document is an object (use cases: catalog).
• Graph model: This class of databases uses structures like data modes, edges and properties, making it easier to model relationships between
entities in an application (use cases: recommendation engines).
• Key-value model: In this NoSQL database model, a key is required to retrieve and update data. The key-value data model is very simple and
therefore scales well. However, this simplicity and scalability come at the cost of query complexity (use cases: shopping cart).
• Wide-column model: Wide-column stores use the typical tables, columns, and rows, but unlike relational databases (RDBs), columnal formatting
and names can vary from row to row inside the same table. And each column is stored separately on disk.
Structured Query Language (SQL) is a standard computer language for accessing and manipulating databases in
Relational Database Management System.
This language is used to query, update and manage relational databases, create a database schema and modify it,
control access to database etc. SQL statements are used to retrieve and update data in a database.
N O T E : S Q L I S N E I T H E R A D A TA B A S E M A N A G E M E N T S Y S T E M N O R A S TA N D A L O N E S O F T W A R E P R O D U C T.
SQL became a standard of the American National Standards Institute (ANSI) in 1986, and of the International Organization for Standardization (ISO)
in 1987.
Although SQL is an ANSI/ISO standard, there are different versions of the SQL language.
However, to be compliant with the ANSI standard, they all support at least the major commands (such as SELECT, UPDATE, DELETE, INSERT, WHERE)
in a similar manner.
NOTE: M O S T O F T H E S Q L D A TA B A S E P R O G R A M S A L S O H A V E T H E I R O W N P R O P R I E TA R Y
E X T E N S I O N S I N A D D I T I O N T O T H E S Q L S TA N D A R D !
Data
Manipulation
Language
Data (DML) Data Control
Definition
Language
Language
(DCL)
(DDL)
Transaction
Data query
language
(DQL)
SQL Control
Language
(TCL)
• Data Query Language (DQL) - SQL commands used to perform • Data Control Language (DCL) – SQL commands used to control
queries on the data within schema objects. The purpose of DQL access to data stored in a database (rights, permissions and other
commands is to get the schema relation based on the query controls).
passed to it.
Example: GRANT, REVOKE
Example: SELECT
• Data Query Language (DQL) - SQL commands used to perform • Data Control Language (DCL) – SQL commands used to control
queries on the data within schema objects. The purpose of DQL access to data stored in a database (rights, permissions and other
commands is to get the schema relation based on the query controls).
passed to it.
Example: GRANT, REVOKE
Example: SELECT
NOTE: The syntax of the SQL programming language is defined and maintained by standard. Despite the existence of the standard, SQL
code is not completely portable among different database systems without adjustments.
Most of the actions you need to perform on a database are done with SQL statements.
Some database systems require a semicolon at the end of each SQL statement. Semicolon is the standard way to separate each SQL
statement in database systems that allow more than one SQL statement to be executed in the same call to the server.
The CREATE DATABASE statement is used to create a new SQL Tip: Make sure you have admin privilege before creating any
database. database. Once a database is created, you can check it in the list
of databases with the following SQL command:
Syntax:
CREATE DATABASE databasename; SELECT * FROM SYS.databases;
The DROP DATABASE statement is used to drop an existing SQL The following SQL statement drops the existing database "testDB":
database.
DROP DATABASE testDB;
Syntax:
Tip: Make sure you have admin privilege before dropping any
DROP DATABASE databasename; database. Once a database is dropped, you can check it in the list of
databases with the following SQL command: SELECT * FROM
Note: Be careful before dropping a database. Deleting a database will
SYS.databases;
result in loss of complete information stored in the database!
The BACKUP DATABASE statement is used in SQL Server to create a full The following SQL statement creates a full back up of the existing
back up of an existing SQL database. database "testDB" to the D disk:
A differential back up only backs up the parts of the database that The following SQL statement creates a differential back up of the
have changed since the last full database backup. database "testDB":
TIPS!
ALWAYS BACK UP THE DATABASE TO A DIFFERENT DRIVE THAN THE ACTUAL DATABASE. THEN, IF YOU GET A DISK CRASH, YOU
WILL NOT LOSE YOUR BACKUP FILE ALONG WITH THE DATABASE.
A DIFFERENTIAL BACK UP REDUCES THE BACK UP TIME (SINCE ONLY THE CHANGES ARE BACKED UP).
CONFIDENTIAL | © 2021 EPAM Systems, Inc. 31
Schema in SQL
A Schema in SQL is a collection of database objects associated with Advantages of using Schema
a database.
You can apply security permissions for separating and protecting
The username of a database is called a Schema owner (owner of database objects based on user access rights.
logically grouped structures of data).
A logical group of database objects can be managed within a database.
Schema always belong to a single database whereas a database can Schemas play an important role in allowing the database objects to be
have single or multiple schemas. organized into these logical groups.
The schema also helps in situations where the database object name is
the same. But these objects fall under different logical groups.
The CREATE SCHEMA Statement is used to create a new SQL schema The following SQL statement creates a schema called "Business" that
under an existing database. is owned by user "dbo":
The schema in a database can be altered by using the ALTER SCHEMA The following example modifies the Schema "HumanResources" by
statement. This statement is specifically used to rename a schema. The transferring the table Address from schema" Person" into the
new owner must be a pre-existing user. "HumanResources" schema.
ALTER SCHEMA schema_name ALTER SCHEMA HumanResources
TRANSFER [ <entity_type> :: ] securable_name ; TRANSFER Person.Address;
The CREATE TABLE statement is used to create a new table in a A copy of an existing table can also be created using CREATE TABLE.
database.
The new table gets the same column definitions. All columns or
Syntax: specific columns can be selected.
CREATE TABLE table_name ( If you create a new table using an existing table, the new table will be
column1 datatype, filled with the existing values from the old table.
column2 datatype,
Syntax:
column3 datatype,
.... CREATE TABLE new_table_name AS
); SELECT column1, column2,...
FROM existing_table_name
The column parameters specify the names of the columns of the
WHERE ....;
table.
The datatype parameter specifies the type of data the column can
hold (e.g. varchar, integer, date, etc.).
The DROP TABLE statement is used to drop an existing table in a The TRUNCATE TABLE statement is used to delete the data
database. inside a table, but not the table itself.
Syntax: Syntax:
DROP TABLE table_name; TRUNCATE TABLE table_name;
Note: Be careful before dropping a table. Deleting a table will
result in loss of complete information stored in the table!
The following SQL statement drops the existing table
“TestTable":
DROP TABLE TestTable;
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.
To add a column in a table, use the following syntax:
ALTER TABLE table_name
ADD column_name datatype;
To delete a column in a table, use the following syntax (notice that some database systems don't allow deleting a column):
ALTER TABLE table_name
DROP COLUMN column_name;
To change the data type of a column in a table, use the following syntax:
ALTER TABLE table_name
ALTER COLUMN column_name datatype;
PersonID LastName FirstName Address City DateOfBirth PersonID LastName FirstName Address City
Data Manipulation Language (DML) - SQL commands used to manipulate/modify data presented in the database.
Example: INSERT, UPDATE, DELETE
If a table contains an auto-increment field it will be generated automatically when a new record is inserted into the table.
The following SQL statement inserts a new record in the “Customers” table:
INSERT INTO Customers (CustomerID, CompanyName, ContactName, Address, City, PostalCode, Country)
VALUES (12345, 'Cardinal', 'Tom Erichsen', 'Skagen 21', 'Stavanger', '4006', 'Norway');
The following SQL statement inserts a new record in the “Customers” table:
INSERT INTO Customers (CustomerID, CompanyName, ContactName, Address, City, PostalCode, Country)
VALUES (12345, 'Cardinal', 'Tom Erichsen', 'Skagen 21', 'Stavanger', '4006', 'Norway');
Note: Be careful when updating records in a table! Notice the WHERE clause in the UPDATE statement. The WHERE clause specifies
which record(s) that should be updated. If you omit the WHERE clause, all records in the table will be updated!
The following SQL statement updates the first customer (id = ‘123’) with a new contact person and a new city.
UPDATE Customers
SET ContactName = 'Alfred Schmidt’,
City = 'Frankfurt’
WHERE CustomerID = '123';
It is the WHERE clause that determines how many records will be updated.
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';
WARNING! Be careful when updating records. If you omit the WHERE clause, ALL records will be updated!
UPDATE Customers
SET ContactName = 'Juan'
Note: Be careful when deleting records in a table! Notice the WHERE clause in the DELETE statement. The WHERE clause specifies which
record(s) should be deleted. If you omit the WHERE clause, all records in the table will be deleted!
The following SQL statement deletes customers which have ContactName " Tom Erichsen " from the "Customers" table:
It is possible to delete all rows in a table without deleting the table. This means that the table structure, attributes, and
indexes will be intact:
Syntax:
DELETE FROM table_name;
It is possible to delete all rows in a table without deleting the table. This means that the table structure, attributes, and indexes will be
intact:
Syntax:
DELETE FROM table_name;
The following SQL statement deletes all rows in the "Customers" table, without deleting the table:
DML (Data Manipulation Language) : The SQL commands that deals with the manipulation of data present in the
database belong to DML or Data Manipulation Language and this includes most of the SQL statements.
Examples of DML:
INSERT – is used to insert data into a table
UPDATE – is used to update existing data within a table
DELETE – is used to delete records from a database table
The SELECT statement is used to select data (read and return it) from a database.
The data returned is stored in a result table, called the result-set. You can perform the same actions on a result set as
on a regular table.
SELECT Syntax:
SELECT column1, column2, ...
FROM table_name;
Here, column1, column2, ... are the field names of the table you want to select data from.
If you want to select all the fields available in the table, use the following syntax:
SELECT * FROM table_name;
The following SQL statement selects the "CustomerName" and "City" The following SQL statement selects all the columns from the
“Customers" table:
columns from the "Customers" table:
SELECT * FROM Customers;
SELECT CompanyName, ContactName, City
FROM Customers;
The SELECT DISTINCT statement is used to return only distinct The following SQL statement selects only the DISTINCT values from the
(different) values. "City" column in the "Customers" table:
FROM Customers;
SELECT DISTINCT Syntax:
1) FROM The following steps show the logical processing order, or binding
order, for a SELECT statement. This order determines when the
2) ON objects defined in one step are made available to the clauses in
3) JOIN subsequent steps.
4) WHERE Because the SELECT clause is step 7, any column aliases or derived
columns defined in that clause cannot be referenced by preceding
5) GROUP BY
clauses. However, they can be referenced by subsequent clauses
6) HAVING such as the ORDER BY clause. The actual physical execution of the
statement is determined by the query processor and the order may
7) SELECT
vary from this list.
8) DISTINCT
The listed sequence is usually true. However, there are uncommon
9) ORDER BY cases where the sequence may differ.
10)TOP
The SELECT INTO statement copies data from one table into a new table.
Syntax:
Tip: SELECT INTO can also be used to create a new, empty table
Copy all columns into a new table:
using the schema of another. Just add a WHERE clause that
SELECT * causes the query to return no data:
INTO newtable
FROM oldtable SELECT * INTO newtable
WHERE condition; FROM oldtable
WHERE 1 = 0;
Copy only some columns into a new table:
SELECT column1, column2, column3, ...
INTO newtable
FROM oldtable
WHERE condition;
The new table will be created with the column-names and types as defined in the old table. You can create new column names using
the AS clause.
The following SQL statement copies only a few columns into a new table:
SELECT CompanyName, ContactName INTO CustomersBackup
FROM Customers;
NOTE: You can add WHERE, JOIN and other Clauses to your SELECT INTO Statement, just like to usual SELECT Statement.
The INSERT INTO SELECT statement copies data from one table and inserts it into another table.
The INSERT INTO SELECT statement requires that the data types in source and target tables matches.
Syntax:
Copy all columns from one table to another table:
Copy only some columns from one table into another table:
The following SQL statement copies "Suppliers" into "Customers" (the columns that are not filled with data, will contain NULL):
The following SQL statement copies "Suppliers" into "Customers" (fill all columns):
INSERT INTO Customers (CustomerID, CompanyName, ContactName, Address, City, PostalCode, Country)
SELECT SupplierID, CompanyName, ContactName, Address, City, PostalCode, Country FROM Suppliers;
NOTE: You can add WHERE, JOIN and other Clauses to your SELECT INTO Statement, just like to usual SELECT Statement.
The WHERE clause is used to filter records, which means to extract THE FOLLOWING OPERATORS CAN BE USED IN WHERE CLAUSE:
only those records that fulfill a specified condition.
WHERE Syntax: Operator Description
However, numeric fields should not be enclosed in quotes. <> Not equal. Note: In some versions of SQL this operator
may be written as !=
The following SQL statement selects all the customers from the city The following SQL statement selects all employees with employee id 1,
"Mexico D.F.", in the "Customers" table: in the “Employees" table:
SELECT CompanyName, Country SELECT * FROM Employees
FROM Customers WHERE EmployeeID=1;
WHERE Country=‘Mexico D.F.’;
The BETWEEN operator selects values within a given range. The values The following SQL statement selects all products with a price between
can be numbers, text, or dates. 10 and 20:
The BETWEEN operator is inclusive: begin and end values are included.
SELECT * FROM Products
WHERE Price BETWEEN 10 AND 20;
BETWEEN Syntax
SELECT column_name(s)
FROM table_name
WHERE column_name BETWEEN value1 AND value2;
The IN operator allows you to specify multiple values in The following SQL statement selects all customers that are located in
a WHERE clause. "Germany", "France" or "UK":
SELECT column_name(s)
FROM table_name
WHERE column_name IN (value1, value2, ...);
or:
SELECT column_name(s)
FROM table_name
WHERE column_name IN (SELECT STATEMENT);
The LIKE operator is used in a WHERE clause to search for a specified The following SQL statement selects all customers with a
pattern in a column. CustomerName starting with "a":
The percent sign and the underscore can also be used in combinations!
LIKE Syntax:
The WHERE clause can be combined with AND, OR, and NOT AND Syntax:
operators.
SELECT column1, column2, ...
The AND and OR operators are used to filter records based on more FROM table_name
than one condition: WHERE condition1 AND condition2 AND condition3 ...;
The AND operator displays a record if all the conditions separated by OR Syntax:
AND are TRUE.
SELECT column1, column2, ...
The OR operator displays a record if any of the conditions separated FROM table_name
by OR is TRUE. WHERE condition1 OR condition2 OR condition3 ...;
The NOT operator displays a record if the condition(s) is NOT TRUE. NOT Syntax:
SELECT column1, column2, ...
N OTE: YOU CA N COMB I N E THE A N D, OR
FROM table_name
A N D N O T O P E R ATO R S . WHERE NOT condition;
The following SQL statement selects all fields from "Customers" The following SQL statement selects all fields from "Customers"
where country is "USA" AND city must be "Portland" OR "Seattle" OR where country is NOT "Germany" and NOT "USA":
"San Francisco"(use parenthesis to form complex expressions):
SELECT * FROM Customers
SELECT * WHERE NOT Country='Germany’
FROM Customers AND NOT Country='USA';
WHERE Country='USA' AND (City = 'Seattle'
OR City = 'Portland'
OR City = 'San Francisco');
Parentheses
AND
OR
The ORDER BY keyword is used to sort the result-set in ascending or ORDER BY Syntax:
descending order.
SELECT column1, column2, ...
The ORDER BY keyword sorts the records in ascending order by FROM table_name
default. To sort the records in descending order, use the DESC ORDER BY column1, column2, ... ASC|DESC;
keyword. OR
NOTE: when you sort by multiple columns, don`t forget to clearly
SELECT column1, column2, ...
identify sort direction for each of them.
FROM table_name
For example:
ORDER BY 1, 2, ... ASC|DESC;
ORDER BY column1, column2 DESC
IS EQUIVALENT TO:
ORDER BY column1 ASC, column2 DESC
In ORDER BY statement you can use column aliases or numbers of
columns in SELECT statement
N O T E : N O T A L L D ATA B A S E S Y S T E M S S U P P O R T T H E S E L E C T T O P C L A U S E .
M y S Q L S UP P O R T S L I M I T C L A US E TO S E L E C T A L I M I T E D N UM B E R O F R E C O R D S ,
W H I L E O R A C L E U S E S F E T C H F I R S T n R O W S O N LY A N D R O W N U M .
The SELECT TOP clause is used to specify the number of records to return.
It is useful on large tables with thousands of records. Returning a large number of records can impact performance.
SELECT TOP Syntax:
SELECT TOP number|percent column_name(s)
FROM table_name
WHERE condition;
The following SQL statement selects the first three records from the The following SQL statement selects the first 50% of the records from
"Customers" table, where the country is "Germany": the "Customers" table:
SELECT TOP 3 * SELECT TOP 50 PERCENT *
FROM Customers FROM Customers;
WHERE Country='Germany';
The OFFSET and FETCH clauses are the options of the ORDER BY The OFFSET clause specifies the number of rows to skip before starting
clause. They allow you to limit the number of rows to be returned by to return rows from the query. The offset_row_count can be a
a query. constant, variable, or parameter that is greater or equal to zero.
The FETCH clause specifies the number of rows to return after the
OFFSET clause has been processed. The offset_row_count can a
OFFSET and FETCH Syntax:
constant, variable or scalar that is greater or equal to one.
The OFFSET clause is mandatory while the FETCH clause is optional.
ORDER BY column_list [ASC |DESC] Also, the FIRST and NEXT are synonyms respectively so you can use
OFFSET offset_row_count {ROW | ROWS} them interchangeably. Similarly, you can use the FIRST and NEXT
interchangeably.
FETCH {FIRST | NEXT} fetch_row_count {ROW | ROWS} ONLY.
NOTE THAT YOU MUST USE THE OFFSET AND FETCH CLAUSES WITH
THE ORDER BY CLAUSE. OTHERWISE, YOU WILL GET AN ERROR.
N O T E : A N U L L V A L U E I S D I F F E R E N T F R O M A Z E R O V A L U E O R A F I E L D T H A T C O N TA I N S
S PA C E S .
A F I E L D W I T H A N U L L VA L U E I S O N E T H AT H A S B E E N L E F T B L A N K D U R I N G R E C O R D C R E AT I O N !
The following SQL lists all customers with a NULL value in the “Region"
field:
SQL aliases are used to give a table, or a column in a table, a temporary name.
Aliases are often used to make column names more readable.
An alias only exists for the duration of the query.
The following SQL statement creates two aliases, one for the CustomerID column and one for the CompanyName column:
Example:
SELECT CustomerID AS ID, CompanyName AS Customer
FROM Customers;
The following SQL statement creates two aliases, one for the CustomerID column and one for the CompanyName column:
Example:
SELECT CustomerID AS ID, CompanyName AS Customer
FROM Customers;
The following SQL statement creates two aliases, one for the CompanyName column and one for the ContactName column.
(Note: It requires double quotation marks or square brackets if the alias name contains spaces)
Example:
SELECT CompanyName AS Customer, ContactName AS [Contact Person]
FROM Customers;
The following SQL statement creates an alias named "Address" that combine four columns (Address, PostalCode, City and Country):
Example:
SELECT CompanyName, Address + ', ' + PostalCode + ' ' + City + ', ' + Country AS Address
FROM Customers;
The following SQL statement selects all the orders from the customer with CustomerID=4 (Around the Horn). We use the "Customers" and "Orders"
tables, and give them the table aliases of "c" and "o" respectively (Here we use aliases to make the SQL shorter):
The following SQL statement selects all the orders from the customer with CustomerID=4 (Around the Horn). We use the "Customers" and "Orders"
tables, and give them the table aliases of "c" and "o" respectively (Here we use aliases to make the SQL shorter):
The following SQL statement is the same as above, but without aliases:
SELECT Orders.OrderID, Orders.OrderDate, Customers.CompanyName
FROM Customers, Orders
WHERE Customers.CompanyName='Around the Horn' AND Customers.CustomerID=Orders.CustomerID;
Comments are used to explain sections of SQL statements, or to prevent execution of SQL statements.
Single line comments start with --.
Any text between -- and the end of the line will be ignored (will not be executed).
The following example uses a single-line comment as an explanation:
--Select all:
SELECT * FROM Customers;
The following example uses a single-line comment to ignore the end of a line:
SELECT * FROM Customers -- WHERE City='Berlin’;
The following example uses a single-line comment to ignore a statement:
--SELECT * FROM Customers;
SELECT * FROM Products;
Multi-line comments start with /* and end with */. To ignore just a part of a statement, also use the /* */ comment.
Any text between /* and */ will be ignored.
The following example uses a comment to ignore part of a line:
The following example uses a multi-line comment as an
explanation: SELECT CompanyName, /*City,*/ Country
/*Select all the columns FROM Customers;
of all the records The following example uses a comment to ignore part of a
in the Customers table:*/ statement:
SELECT * FROM Customers;
SELECT * FROM Customers
The following example uses a multi-line comment to ignore WHERE (CompanyName LIKE 'L%’
many statements: OR CompanyName
/*SELECT * FROM Customers; LIKE 'R%' /*OR CompanyName LIKE 'S%’
SELECT * FROM Products; OR CustomerName LIKE 'T%’*/
SELECT * FROM Orders; OR CompanyName LIKE 'W%’)
SELECT * FROM Categories;*/ AND Country='USA’
SELECT * FROM Suppliers; ORDER BY CompanyName;
1) Download the bak file from link provided in the download section.
2) Move the bak file to your SQL Server backup location (this varies depending on your installation location, instance name and version of
SQL Server. For example, the default location for a default instance of SQL Server 2019 is: C:\\Program Files
Microsoft\SQLServer\MSSQL15.MSSQLSERVER\MSSQL\Backup
3) Open SQL Server Management Studio (SSMS) and connect to your SQL Server in.
4) Right click Databases in Object Explorer > Restore Database... to launch the Restore
Database wizard.
7) Select OK to confirm your database backup selection and close the Select backup devices
window.
8) Check the Files tab to confirm the Restore as location and file names match your
intended location and file names in the Restore Database wizard.
9) Select OK to restore your database.
4 N O R T H W I N D S A M P L E D A TA B A S E
5 S Q L T U TO R I A L