DATABASE MANAGEMENT
SYSTEMS
Introduction To SQL
Lab 1
Instructor: Engr Ayesha Khan
Marking scheme
EVALUATION INSTRUMENTS MARKS
LAB ASSESMENT 30
ASSIGNMENTS 10
LAB FILE 20
PROJECT 30
LAB VIVA 10
TOTAL 100
Software requirements
Sql Server
Follow this link to download and install sql server
Sample Database to be used:
• Northwind
• Pubs
• Adventureworks
Follow this link for installation of northwind db
https://www.youtube.com/watch?v=yasfZuou3zI
INTRODUCTION TO SQL
What is a database?
A database is an organized collection of data.
INTRODUCTION TO SQL
What is a Database Management System?
Database management systems (DBMSs) are specially designed
software applications that interact with the user, other applications, and
the database itself to capture and analyze data.
Well-known DBMSs include MySQL, MariaDB, PostgreSQL, SQLite,
Microsoft SQL Server, Oracle, SAP, dBASE, FoxPro, IBM DB2,
LibreOffice Base and FileMaker Pro.
INTRODUCTION TO SQL
What is a Server?
A server is a computer that serves information to other computers.
These other computers are called clients.
Connected through a local area network (LAN) or a wide area network
(WAN), such as the Internet.
INTRODUCTION TO SQL
What is a Record?
A complete set of information.
Records are composed of fields.
INTRODUCTION TO SQL
What is a field?
A space allocated for a particular item or information.
A collection of fields is called a record.
INTRODUCTION TO SQL
What is SQL?
SQL stands for Structured Query LanguageSQL lets you access and manipulate databases.
What Can SQL do?
SQL can execute queries against a database
SQL can retrieve data from a database
SQL can insert records in a database
SQL can update records in a database
SQL can delete records from a database
SQL can create new databases
SQL can create new tables in a database
INTRODUCTION TO SQL
The SELECT ... FROM Clause
The most basic SELECT statement has only 2 parts:
(1) the columns you want to display and
(2) from the table(s) these columns belong to.
EXAMPLE 1
SELECT EmployeeID, FirstName, LastName, HireDate, City FROM
Employees
Select * from Employees
Where Clause
By adding a WHERE clause to the SELECT
statement, we add one (or more) conditions that
must be met by the selected data. This will limit
the number of rows that answer the query and are
fetched. In many cases, this is where most of the
"action" of a query takes place.
Operators
There are four types of operators:
1. Comparison Operators
2. Logical Operators
3. List Operators
4. Range Operators
Operator
An operator is a character or a reserved word that
is used to specify a condition, or combine two or
more conditions. The operators are used with the
WHERE clause in the SELECT statement to set
the filter criteria for data.
Comparison Operator
Comparison operators are used to compare the column
data with specific values in a condition.
Comparison Operator Description
= Equal to
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to
<> Not equal to
SQL WHERE and OPERATOR Syntax
SELECT column_name,column_name FROM
table_name WHERE column_name operator
value
Equal to
SELECT EmployeeID, FirstName, LastName,
HireDate, City FROM Employees WHERE City
= 'London';
Greater than or equal to
SELECT ProductName,UnitsInStock,UnitsOnOrder
FROM Products WHERE UnitsOnOrder >=70
Not equal to
If you wanted to get the opposite, the employees
who do not live in London, you would write
Not equal to
SELECT EmployeeID, FirstName, LastName,
HireDate, City FROM Employees WHERE City
<> 'London'
Logical Operators
Logical operators are used to test if a specified condition is true or not. They are also
used to combine multiple conditions.
Some of the commonly used logical operators are:
OR
• Retrieves rows that meet any one of the specified conditions.
AND
• Retrieves rows that meet both the conditions.
NOT
• Retrieves rows that do not meet the specified condition.
BETWEEN
• Retrieves rows where the tested value falls within the specified range.
OR OPERATOR
SELECT CompanyName,City FROM Customers
WHERE City = 'London' OR City = 'Madrid'
AND OPERATOR
SELECT * FROM Customers WHERE
Country='Germany'
AND City='Berlin';
USING AND and OR OPERATOR
SELECT * FROM Customers WHERE
Country='Germany' AND (City='Berlin' OR
City='Mannheim');
Lab Tasks
• Get Order id, Product id, Unit price from Order Details.
• Find Title of employee Nancy.
• Display data of all employees those working as Sales Representative
from London
• Display product name whose unit price are greater than 90$
• Write a query to get current Product list (Product ID and name).
• Fetch data of customers where country is "Germany" AND city must
be "Berlin" OR "München" (use parenthesis to form complex
expressions)
Lab Tasks
• Fetch data of customers from all countries except Germany and USA
• Fetch Discontinued products who’s price is greater than 20
Lab-1-Introduction-to-SQL-03042020-.pptx

Lab-1-Introduction-to-SQL-03042020-.pptx

  • 1.
    DATABASE MANAGEMENT SYSTEMS Introduction ToSQL Lab 1 Instructor: Engr Ayesha Khan
  • 2.
    Marking scheme EVALUATION INSTRUMENTSMARKS LAB ASSESMENT 30 ASSIGNMENTS 10 LAB FILE 20 PROJECT 30 LAB VIVA 10 TOTAL 100
  • 3.
    Software requirements Sql Server Followthis link to download and install sql server Sample Database to be used: • Northwind • Pubs • Adventureworks Follow this link for installation of northwind db https://www.youtube.com/watch?v=yasfZuou3zI
  • 4.
    INTRODUCTION TO SQL Whatis a database? A database is an organized collection of data.
  • 5.
    INTRODUCTION TO SQL Whatis a Database Management System? Database management systems (DBMSs) are specially designed software applications that interact with the user, other applications, and the database itself to capture and analyze data. Well-known DBMSs include MySQL, MariaDB, PostgreSQL, SQLite, Microsoft SQL Server, Oracle, SAP, dBASE, FoxPro, IBM DB2, LibreOffice Base and FileMaker Pro.
  • 6.
    INTRODUCTION TO SQL Whatis a Server? A server is a computer that serves information to other computers. These other computers are called clients. Connected through a local area network (LAN) or a wide area network (WAN), such as the Internet.
  • 7.
    INTRODUCTION TO SQL Whatis a Record? A complete set of information. Records are composed of fields.
  • 8.
    INTRODUCTION TO SQL Whatis a field? A space allocated for a particular item or information. A collection of fields is called a record.
  • 9.
    INTRODUCTION TO SQL Whatis SQL? SQL stands for Structured Query LanguageSQL lets you access and manipulate databases. What Can SQL do? SQL can execute queries against a database SQL can retrieve data from a database SQL can insert records in a database SQL can update records in a database SQL can delete records from a database SQL can create new databases SQL can create new tables in a database
  • 10.
    INTRODUCTION TO SQL TheSELECT ... FROM Clause The most basic SELECT statement has only 2 parts: (1) the columns you want to display and (2) from the table(s) these columns belong to.
  • 11.
    EXAMPLE 1 SELECT EmployeeID,FirstName, LastName, HireDate, City FROM Employees Select * from Employees
  • 12.
    Where Clause By addinga WHERE clause to the SELECT statement, we add one (or more) conditions that must be met by the selected data. This will limit the number of rows that answer the query and are fetched. In many cases, this is where most of the "action" of a query takes place.
  • 13.
    Operators There are fourtypes of operators: 1. Comparison Operators 2. Logical Operators 3. List Operators 4. Range Operators
  • 14.
    Operator An operator isa character or a reserved word that is used to specify a condition, or combine two or more conditions. The operators are used with the WHERE clause in the SELECT statement to set the filter criteria for data.
  • 15.
    Comparison Operator Comparison operatorsare used to compare the column data with specific values in a condition. Comparison Operator Description = Equal to > Greater than < Less than >= Greater than or equal to <= Less than or equal to <> Not equal to
  • 16.
    SQL WHERE andOPERATOR Syntax SELECT column_name,column_name FROM table_name WHERE column_name operator value
  • 17.
    Equal to SELECT EmployeeID,FirstName, LastName, HireDate, City FROM Employees WHERE City = 'London';
  • 18.
    Greater than orequal to SELECT ProductName,UnitsInStock,UnitsOnOrder FROM Products WHERE UnitsOnOrder >=70
  • 19.
    Not equal to Ifyou wanted to get the opposite, the employees who do not live in London, you would write
  • 20.
    Not equal to SELECTEmployeeID, FirstName, LastName, HireDate, City FROM Employees WHERE City <> 'London'
  • 21.
    Logical Operators Logical operatorsare used to test if a specified condition is true or not. They are also used to combine multiple conditions. Some of the commonly used logical operators are: OR • Retrieves rows that meet any one of the specified conditions. AND • Retrieves rows that meet both the conditions. NOT • Retrieves rows that do not meet the specified condition. BETWEEN • Retrieves rows where the tested value falls within the specified range.
  • 22.
    OR OPERATOR SELECT CompanyName,CityFROM Customers WHERE City = 'London' OR City = 'Madrid'
  • 23.
    AND OPERATOR SELECT *FROM Customers WHERE Country='Germany' AND City='Berlin';
  • 24.
    USING AND andOR OPERATOR SELECT * FROM Customers WHERE Country='Germany' AND (City='Berlin' OR City='Mannheim');
  • 25.
    Lab Tasks • GetOrder id, Product id, Unit price from Order Details. • Find Title of employee Nancy. • Display data of all employees those working as Sales Representative from London • Display product name whose unit price are greater than 90$ • Write a query to get current Product list (Product ID and name). • Fetch data of customers where country is "Germany" AND city must be "Berlin" OR "München" (use parenthesis to form complex expressions)
  • 26.
    Lab Tasks • Fetchdata of customers from all countries except Germany and USA • Fetch Discontinued products who’s price is greater than 20