First Lab Class Handouts - To Upload
First Lab Class Handouts - To Upload
DBMS
Tools
1. Microsoft SQL Server
2. Oracle
3. MySQL
Versions:
SQL Server 2019 Windows 8
Windows 10
Latest version available.
64 Bit os
SQL Server 2016 Windows 7 (2016)
SQL Server 2014
SQL Server 2012 Obsolete version:
About these versions, Microsoft
has stopped supporting these.
*Out of Support
SQL Server Downloads | Microsoft
SSMS
https://docs.microsoft.com/en-us/sql/ssms/download-sql-server-management-studio-ssms?
redirectedfrom=MSDN&view=sql-server-ver15
1.Developer
Express Developer
Entry Level For people who build but also
test applications
Ideal for learning and building Enterprise Level
small scaled applications
(desktop and web)
For Khalid:
MSSQLSERVER
Local Server or
127.0.0.1/Irfan343016056997
Server Name:
/localhost/SQLEXPRESS
But For
*SQL Server Authentication, you need a username and
password.
Difference between …
RDBMS DBMS
Store data in a tabular Holds or store data as file
form.
Here there is a No relationship between
relationship between data these files.
stored in tables.
Data:
Its about facts to any object like your name, your age,
your height, your weight etc
Database:
Is a systematic collection of data. In this way, we can
make data management easy.
Facebook:
Store, manipulate data
Telephonic directory:
1. People
2. Phone numbers
3. Other contact details
14-02-2021
Operators:
AND
OR
IN
BETWEEN
LIKE
NULL
SELECT
product_id,
product_name,
category_id,
model_year,
list_price
from production.products
where category_id = 6
order by
list_price desc;
SELECT
product_id,product_name,
category_id,model_year,list_price
from production.products
SELECT
product_id,product_name,
category_id,model_year,list_price
from production.products
where list_price > 350 AND model_year =
2018
order by
list_price desc;
SELECT
product_id,product_name,
category_id,model_year,list_price
from production.products
SELECT
product_id,product_name,
category_id,model_year,list_price
from production.products
SELECT
product_id,product_name,
category_id,model_year,list_price
from production.products
select
first_name,
last_name, phone
from sales.customers
where phone IS NULL
order by
first_name,
last_name;
select
first_name,
last_name, phone
from sales.customers
where phone IS NOT NULL
order by
first_name,
last_name;
select *
from production.products
where
(brand_id = 1 OR brand_id = 2)
AND list_price > 1000
order by list_price desc;
select *
from production.products
where
brand_id = 1
OR brand_id = 2
OR brand_id = 4
order by brand_id desc;
order by
brand_id desc;
DESC
Descending order
OFFSET -
This Clause is used to limit the
FETCH Clause number of rows.
FTECH Clause
select
product_name,
list_price
from
production.products
order by
list_price,
product_name
Offset 10 rows
fetch next 5 rows only;
SELECT TOP
statement
It allows you to limit the number of
rows or percentage of rows returned.
select top 10
product_name,
list_price
from
production.products
order by
list_price DESC;
select distinct
city
from sales.customers
order by
city;
select distinct
city, state
from sales.customers
Select DISTINCT order by
city,
Clause state;
With multiple
columns
ASC/DESC
The ASC sorts the result from the
lowest value to the highest value.
CREATE DATABASE
How to create a new database
>CREATE DATABASE TestDb;
DROP DATABASE
How to remove a database
>DROP DATABASE IF EXISTS TestDb;
BACKUP DATABASE
Create a full backup of an existing Database
>BACKUP DATABASE TestDb1
TO DISK = ‘Filepath’
WITH DIFFERENTIAL;
>BACKUP DATABASE TestDb1 TO DISK = 'C:\
BackupDB\TestDb1.bak';
NOTE:
WITH DIFFERENTIAL: It reduces the backup time because it
copies only the changes.
BACKUP DATABASE TestDb1
TO DISK = 'C:\BackupDB\TestDb1.bak'
WITH DIFFERENTIAL;
CREATE TABLE
Tables are used to store data in the database and
each table has its unique name.
Student Table:
Name ID Address Mobile
Mosa 123 Buraydah 123
Abdullah 456 Alras 456
NOTE:
Be careful before dropping or deleting a table, why?
Because if the table contains information, the
complete information will result in loss.
TRUNCATE TABLE
INSERT INTO
insert into Student (Name, ID, Address, Mobile)
values ('Abdullah', '123', 'Buraydah', '123');
DATA TYPES
In SQL Server, a column, variable and parameter
holds a value that associated with a type. A data
type is an attribute that specifies the type of data.
numeric(p,s)
p= for precision
s= scale numbers
date
store a date only. (3 bytes)
int
4 bytes
varchar (size)
A variable length string (contain letters, numbers,
and special characters). The size in characters is
from 0-65535.
varchar2 (size)
varchar and varchar2 are same string type datatypes
but varchar2 considers NULL and EMPTY string
same.
char(size)
0-255 characters
CREATE TABLE dept
(
deptno int,
dname varchar(14),
loc varchar(13)
);