Find Top SQL Developers today. Toptal can match you with the best engineers to finish your project. Or, match you with the best companies that need your SQL skills today!
Database Testing involves the testing of database triggers and logical views which are going to support database refactoring. It performs module testing of database functions, triggers, views, SQL queries etc. It validates database tables, data models, database schema etc. It checks rules of Referential integrity.
Find Top SQL Developers today. Toptal can match you with the best engineers to finish your project. Or, match you with the best companies that need your SQL skills today!
Database Testing involves the testing of database triggers and logical views which are going to support database refactoring. It performs module testing of database functions, triggers, views, SQL queries etc. It validates database tables, data models, database schema etc. It checks rules of Referential integrity.
An introduction to SQL standard language for beginners and non-technical information people. Mostly covers SELECT statement using standard clauses, Joins, Sub-Queries and ...
AimTo give you practical experience in database modelling, no.docxsimonlbentley59018
Aim:
To give you practical experience in database modelling, normalization and writing SQL statements to query a relational database
Assignment Summary:
The project specification details provided in this document and you must use only given specifications to come up with your solution. Make appropriate assumptions where ever required.
Please make sure that your group must meet your lecturer/tutor at least twice to update the progress of your assignment.
Background Information for Sample Database Project:
Australian Manufacturing Company (AMC) requires a database system to manage their stores, employees, products, suppliers, patrons and orders.
The following information has been gathered about current business activities of AMC.
AMC has many stores in different cities across Australia. Each store has unique store number and other details like name, contact details (phone number, email address and fax number) and location details (postal address composed of street number, suburb, state and postcode).
There are many departments within each store, for example, HR, accounts, finance and sales etc. each department is uniquely identified by department number. AMC also records department title, phone number and email address.
Each store has a number of employees. Each department is supervised by a department supervisor and each store is managed by a store manager who both are employees of AMC. Each department has a single supervisor only i.e. the department supervisor is also the supervisor for all the employees work within that department.
Each employee is referenced by unique employee number, name (first and last names), address, mobile number, email, TFN, salary and joining date. An employee’s salary is recorded differently as per his or her employment type. Employees can be employed as fulltime or casual basis. For a fulltime staff, annual salary is recorded and hourly rate for a casual staff.
Each store creates payslips for all employees work in that store on a weekly basis. As a minimum payslip number, no of hours worked, employee detail, store detail and gross pay are recorded.
AMC sales different products like fashion, health, beauty, electronics etc. Each product is characterised by product number, name, brand, description and price.
Each product can be supplied by one or more supplier and each supplier can supply one or many products. AMC also keeps appropriate details of their suppliers.
Each store maintains an inventory of their products available for sale. The quantity of each product available in store and the quantity ordered are kept.
AMC patron visits the store and shops in the store. Each customer is characterised by customer number, name (first and last names), mobile number and address.
A patron may place orders. An order contains one or many products at a time. A store keeps track of order number, order date, product(s) ordered and quantity ordered for each product.
2 | P a g e
The proprietors of AMC have ap.
SELECT
FROM
AS
DISTINCT
Arithmetic Operations on Columns
WHERE Clause
Comparison Operators (<,>,<=,>=,<>,=)
Other Operators
BETWEEN… AND,
NOT BETWEEN… AND
IN for more info visit utkaluniversity.com
How to use the SELECT DISTINCT statement in SQL
An Introduction, Syntax and Use Cases
SELECT DISTINCT statement by Select Distinct Limited
This will confuse the SEO :)
https://www.selectdistinct.co.uk/2023/03/23/select-distinct-statement-sql/
#selectdistinct #SQL #DataAnalytics
Lamar University - MISY 3310 Access ProjectPremiere Products.docxDIPESH30
Lamar University - MISY 3310
Access Project
Premiere Products – Data Management
Premiere Products is a distributor of appliances, house wares, and sporting goods. Since its inception, the company has used spreadsheet software to maintain customer, order, inventory, and sales representative data. Redundancy and difficulty in accessing related data are the major problems that employees at Premiere Products encounter with the spreadsheets. The company’s business activities have grown significantly in the recent years and it is no longer feasible to use spreadsheets to maintain its data.
The management of Premiere Products has determined that Premiere Products must maintain, in a new database, the following information about its sales representatives, customers, parts inventory, and suppliers:
· Premiere Products must store the sales rep number that uniquely identifies a representative. In addition, it has to store the sales rep last name, first name, address, total commission, and commission rate.
· The company must store the customer number, which uniquely identifies a customer, customer name, address, current balance, and credit limit for each customer, as well as the number of sales representative who represents the customer.
· The company must store the part number, description, number of units on hand, item type, number of the warehouse where the item is stored, and unit price for each part in inventory.
· Premiere Products must store information about the suppliers who supply parts. The supplier is uniquely identified by supplier number. In addition, a supplier has a name, address, city, contact name and telephone number.
Premiere Products must also store information about orders. The orders have three components: The heading (top) of the order contains the order number and the date; the customer’s number, name, and address; and the sales rep number and name. The body of the order contains one or more order lines, sometimes called line items. Each order line contains a part number, a part description, the number of units of the part ordered, and the quoted price for the part. Each order line also contains a total, usually called an extension, which is the result of multiplying the number ordered by the quoted price. Finally, the footing (bottom) of the order contains the order total.
Premiere Products must also store the following items for each customer’s order:
· For each order, they must store the order number, the date the order was placed, and the number of the customer that placed the order. The customer’s name and address and the number of the sales rep who represents the customer are stored with the customer information. The name of the sales rep is stored with the sales rep information.
· For each order line, the database must store the order number, the part number, the number of units ordered, and the quoted price. Remember that the part description is stored with the information about parts. The result of mu ...
An introduction to SQL standard language for beginners and non-technical information people. Mostly covers SELECT statement using standard clauses, Joins, Sub-Queries and ...
AimTo give you practical experience in database modelling, no.docxsimonlbentley59018
Aim:
To give you practical experience in database modelling, normalization and writing SQL statements to query a relational database
Assignment Summary:
The project specification details provided in this document and you must use only given specifications to come up with your solution. Make appropriate assumptions where ever required.
Please make sure that your group must meet your lecturer/tutor at least twice to update the progress of your assignment.
Background Information for Sample Database Project:
Australian Manufacturing Company (AMC) requires a database system to manage their stores, employees, products, suppliers, patrons and orders.
The following information has been gathered about current business activities of AMC.
AMC has many stores in different cities across Australia. Each store has unique store number and other details like name, contact details (phone number, email address and fax number) and location details (postal address composed of street number, suburb, state and postcode).
There are many departments within each store, for example, HR, accounts, finance and sales etc. each department is uniquely identified by department number. AMC also records department title, phone number and email address.
Each store has a number of employees. Each department is supervised by a department supervisor and each store is managed by a store manager who both are employees of AMC. Each department has a single supervisor only i.e. the department supervisor is also the supervisor for all the employees work within that department.
Each employee is referenced by unique employee number, name (first and last names), address, mobile number, email, TFN, salary and joining date. An employee’s salary is recorded differently as per his or her employment type. Employees can be employed as fulltime or casual basis. For a fulltime staff, annual salary is recorded and hourly rate for a casual staff.
Each store creates payslips for all employees work in that store on a weekly basis. As a minimum payslip number, no of hours worked, employee detail, store detail and gross pay are recorded.
AMC sales different products like fashion, health, beauty, electronics etc. Each product is characterised by product number, name, brand, description and price.
Each product can be supplied by one or more supplier and each supplier can supply one or many products. AMC also keeps appropriate details of their suppliers.
Each store maintains an inventory of their products available for sale. The quantity of each product available in store and the quantity ordered are kept.
AMC patron visits the store and shops in the store. Each customer is characterised by customer number, name (first and last names), mobile number and address.
A patron may place orders. An order contains one or many products at a time. A store keeps track of order number, order date, product(s) ordered and quantity ordered for each product.
2 | P a g e
The proprietors of AMC have ap.
SELECT
FROM
AS
DISTINCT
Arithmetic Operations on Columns
WHERE Clause
Comparison Operators (<,>,<=,>=,<>,=)
Other Operators
BETWEEN… AND,
NOT BETWEEN… AND
IN for more info visit utkaluniversity.com
How to use the SELECT DISTINCT statement in SQL
An Introduction, Syntax and Use Cases
SELECT DISTINCT statement by Select Distinct Limited
This will confuse the SEO :)
https://www.selectdistinct.co.uk/2023/03/23/select-distinct-statement-sql/
#selectdistinct #SQL #DataAnalytics
Lamar University - MISY 3310 Access ProjectPremiere Products.docxDIPESH30
Lamar University - MISY 3310
Access Project
Premiere Products – Data Management
Premiere Products is a distributor of appliances, house wares, and sporting goods. Since its inception, the company has used spreadsheet software to maintain customer, order, inventory, and sales representative data. Redundancy and difficulty in accessing related data are the major problems that employees at Premiere Products encounter with the spreadsheets. The company’s business activities have grown significantly in the recent years and it is no longer feasible to use spreadsheets to maintain its data.
The management of Premiere Products has determined that Premiere Products must maintain, in a new database, the following information about its sales representatives, customers, parts inventory, and suppliers:
· Premiere Products must store the sales rep number that uniquely identifies a representative. In addition, it has to store the sales rep last name, first name, address, total commission, and commission rate.
· The company must store the customer number, which uniquely identifies a customer, customer name, address, current balance, and credit limit for each customer, as well as the number of sales representative who represents the customer.
· The company must store the part number, description, number of units on hand, item type, number of the warehouse where the item is stored, and unit price for each part in inventory.
· Premiere Products must store information about the suppliers who supply parts. The supplier is uniquely identified by supplier number. In addition, a supplier has a name, address, city, contact name and telephone number.
Premiere Products must also store information about orders. The orders have three components: The heading (top) of the order contains the order number and the date; the customer’s number, name, and address; and the sales rep number and name. The body of the order contains one or more order lines, sometimes called line items. Each order line contains a part number, a part description, the number of units of the part ordered, and the quoted price for the part. Each order line also contains a total, usually called an extension, which is the result of multiplying the number ordered by the quoted price. Finally, the footing (bottom) of the order contains the order total.
Premiere Products must also store the following items for each customer’s order:
· For each order, they must store the order number, the date the order was placed, and the number of the customer that placed the order. The customer’s name and address and the number of the sales rep who represents the customer are stored with the customer information. The name of the sales rep is stored with the sales rep information.
· For each order line, the database must store the order number, the part number, the number of units ordered, and the quoted price. Remember that the part description is stored with the information about parts. The result of mu ...
This presentation deals with the fundamentals of SQL, Installation and Database concepts. Presented by our team in Alphalogic Inc: https://www.alphalogicinc.com/
• Developed and Analysed Data warehouse Using SSIS ETL tool, SSDT, SQL server
• Provided Analysed Quarterly Report Using SSRS of Total sales, Total Revenue, Predicted Future sales, topmost selling products, top discounted product.
• Used Performance tuning to fetch rows faster from database and performed data visualization using R-studio and Neo-4j.
The Building Blocks of QuestDB, a Time Series Databasejavier ramirez
Talk Delivered at Valencia Codes Meetup 2024-06.
Traditionally, databases have treated timestamps just as another data type. However, when performing real-time analytics, timestamps should be first class citizens and we need rich time semantics to get the most out of our data. We also need to deal with ever growing datasets while keeping performant, which is as fun as it sounds.
It is no wonder time-series databases are now more popular than ever before. Join me in this session to learn about the internal architecture and building blocks of QuestDB, an open source time-series database designed for speed. We will also review a history of some of the changes we have gone over the past two years to deal with late and unordered data, non-blocking writes, read-replicas, or faster batch ingestion.
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...sameer shah
"Join us for STATATHON, a dynamic 2-day event dedicated to exploring statistical knowledge and its real-world applications. From theory to practice, participants engage in intensive learning sessions, workshops, and challenges, fostering a deeper understanding of statistical methodologies and their significance in various fields."
Levelwise PageRank with Loop-Based Dead End Handling Strategy : SHORT REPORT ...Subhajit Sahu
Abstract — Levelwise PageRank is an alternative method of PageRank computation which decomposes the input graph into a directed acyclic block-graph of strongly connected components, and processes them in topological order, one level at a time. This enables calculation for ranks in a distributed fashion without per-iteration communication, unlike the standard method where all vertices are processed in each iteration. It however comes with a precondition of the absence of dead ends in the input graph. Here, the native non-distributed performance of Levelwise PageRank was compared against Monolithic PageRank on a CPU as well as a GPU. To ensure a fair comparison, Monolithic PageRank was also performed on a graph where vertices were split by components. Results indicate that Levelwise PageRank is about as fast as Monolithic PageRank on the CPU, but quite a bit slower on the GPU. Slowdown on the GPU is likely caused by a large submission of small workloads, and expected to be non-issue when the computation is performed on massive graphs.
Enhanced Enterprise Intelligence with your personal AI Data Copilot.pdfGetInData
Recently we have observed the rise of open-source Large Language Models (LLMs) that are community-driven or developed by the AI market leaders, such as Meta (Llama3), Databricks (DBRX) and Snowflake (Arctic). On the other hand, there is a growth in interest in specialized, carefully fine-tuned yet relatively small models that can efficiently assist programmers in day-to-day tasks. Finally, Retrieval-Augmented Generation (RAG) architectures have gained a lot of traction as the preferred approach for LLMs context and prompt augmentation for building conversational SQL data copilots, code copilots and chatbots.
In this presentation, we will show how we built upon these three concepts a robust Data Copilot that can help to democratize access to company data assets and boost performance of everyone working with data platforms.
Why do we need yet another (open-source ) Copilot?
How can we build one?
Architecture and evaluation
Unleashing the Power of Data_ Choosing a Trusted Analytics Platform.pdfEnterprise Wired
In this guide, we'll explore the key considerations and features to look for when choosing a Trusted analytics platform that meets your organization's needs and delivers actionable intelligence you can trust.
Analysis insight about a Flyball dog competition team's performanceroli9797
Insight of my analysis about a Flyball dog competition team's last year performance. Find more: https://github.com/rolandnagy-ds/flyball_race_analysis/tree/main
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Data and AI
Round table discussion of vector databases, unstructured data, ai, big data, real-time, robots and Milvus.
A lively discussion with NJ Gen AI Meetup Lead, Prasad and Procure.FYI's Co-Found
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data LakeWalaa Eldin Moustafa
Dynamic policy enforcement is becoming an increasingly important topic in today’s world where data privacy and compliance is a top priority for companies, individuals, and regulators alike. In these slides, we discuss how LinkedIn implements a powerful dynamic policy enforcement engine, called ViewShift, and integrates it within its data lake. We show the query engine architecture and how catalog implementations can automatically route table resolutions to compliance-enforcing SQL views. Such views have a set of very interesting properties: (1) They are auto-generated from declarative data annotations. (2) They respect user-level consent and preferences (3) They are context-aware, encoding a different set of transformations for different use cases (4) They are portable; while the SQL logic is only implemented in one SQL dialect, it is accessible in all engines.
#SQL #Views #Privacy #Compliance #DataLake
2. ABCCompaniesLimited
CUSTOMERS: Name, Age, Gender, Email Id, Loyalty program member, etc
EMPLOYEES: Name, Age, Gender, Email Id, Title, Pay Scale, Hire date, etc
SUPPLIERS: Name, Address, Contact, Product ID, Price, Units, etc
SHAREHOLDERS: Name, Number of shares owned, percentage of total equity, etc
CREDITORS: Name, type, Days, etc
PRODUCTS: Id, Category, MRP, Units, etc
STORES: ID, Location, Type, Area, etc
SALES: Current Year, Previous Year, YOY, YTD, etc
Let us consider a large retailer
named ABC Companies limited. The
data for such a retailer would
majorly be about its customers,
employees, suppliers, shareholders,
creditors, products, stores and sales
as shown:
These facts, ex: Name-Vin, Age-26,
Units-40, Price-$34.95, etc, or in
other words, these set of values with
respect to the variables is Data.
What is Data?
2
3. Organized Data
A few product Id’s and Units at a particular store of ABC Companies Ltd is as follows:
FD139, 250, FD760 , 375, JH565, 410, KU206, 190, SY408, 200, BK213, 255, FR908, 384, SL650, 293, ZM987,
212, LK209, 368
This form of representation of data becomes confusing when the number of products increase.
Representation of data in a tabular form as shown is easy to interpret and analyse the data.
Product
Id
Units
FD139 250
FD760 375
JH565 410
KU206 190
SY408 200
BK213 255
FR908 384
SL650 293
ZM987 212
LK209 368
Suppose we have data for 1000 product Ids and the company wants to know the product
Ids having more than 250 units.
Unorganized data: Will take a lot of time and resource to gather the required information
Organized data in ascending order of units: Will be very quick and easy to sort out the
required information.
3
4. Database
STORE
Store_ID
Store_Code
Store_Name
Store_Region_ID
Store_Type
STORE BILLING
Bill_Number
Customer_ID
EmployeeID
Store_Billing_Date
Store_Billing_Time
Store_Start_Date
Store_ID
PRODUCTS
ProductID
ProductName
SupplierID
CategoryID
Product Code
Product Country
BrandID
More…
BRAND
BrandID
CategoryID
Brand_Description
STORE REGION
Store_Region_ID
Store_Region_Nmae
Store_County
Store_State
DEPARTMENT
Emp_Department_ID
Department Name
Department Code
Department Description
Department Head
Department_Start_Date
EMPLOYEES
EmployeeID
Emp_Department_ID
Manager_ID
LastName
FirstName
Title
DOB
HireDate
SUPPLIER_TYPE
Supplier_Type_ID
Supplier_Type
Supplier_Description
SUPPLIERS
SupplierID
Supplier_Type_ID
Supplier_Name
Supplier_Location_Manager
Supplier_Region
STORE BILLING
DETAILS
Bill_Number
ProductID
UnitPrice
Quantity
Total Amount
Discount
Storage cost per item
Cost price per item
Labour cost per item
PACKAGING
PackageID
Package_Description
Package_Type
CATEGORIES
CategoryID
CategoryName
Description
Picture
REGION
RegionID
Customers_Region_Description
CUSTOMERS
CustomerID
Customer_Type_ID
Customer_Region_ID
Customer_Shopper_ID
Customer_Full_Name
Customer_First_Name
Customer_Last_Name
Address
City
Region
TERRITORIES
TerritoryID
Customer_Territory_Description
RegionID
CUSTOMER TYPE
Customer_Type_ID
Customer_Type
Customer_Description
Database can be
considered as a cupboard
of organized data.
Each drawer of the
cupboard represents a table
also called an Entity.
Ex: Employees, Products,
Packaging, etc
Each Entity has variables
known as Fields.
Ex: EmployeeID, Title,
DOB, etc are the fields in
the Employees Entity.
Each field has values
known as Data.
Ex: BrandID CategoryID
162 SD125
208 GF326
363 FF118
284 DP251
189 RM318
DATA
4
5. RELATIONAL DATABASE
Each Table/Entity is a Relation as it
contains related data.
Suppose I need a list of Customers with
their ID, Type and store billing details.
• In order to get the customer type, there
needs to be a relation between
Customers and Customer type which is
established based on a common field
which is ‘Customer_Type_ID’.
• Similarly, to get the store billing details,
there should be a relation between
Customers, Store billing and Store
billing details based on a common field
which is ‘CustomerID’ and
‘Bill_Number’ respectively.
A database which lets us look at any of the
entities and allows us to derive more
information through its relation with other
entities is known as a Relational Database.
Note: Fields in Bold are Primary Key 5
6. Relational Database Management System
• RDBMS is a software that can be considered as a gatekeeper to relational database.
• It provides users and programmers with a systematic way to create, retrieve, update and delete data in a
database.
• It ensures that data is consistently organized and remains easily accessible.
Relational Database RDBMS User
ABC Companies Limited
App
6
7. STRUCTURED QUERY LANGUAGE (SQL)
The language used to interact
with a relational database is
known as Structured Query
Language (SQL).
The commands in SQL are
classified in three groups as
shown
Suppose we want to create a
database called ‘ABCretail’.
We can use the following
commands to create, see and
select the database
respectively.
SQLCommands
Data Definition Language
(DDL)
Data Manipulation Language
(DML)
Data Control Language
(DCL)
CREATE
ALTER
DROP
SELECT
UPDATE
INSERT
DELETE
GRANT
REVOKE
Create database ABCretail; >>This will create a database called ‘ABCretail’
Use ABCretail; >>This will select ‘ABCretail’ as the database for data retrieval.
Drop database ABCretail; >> This will delete ‘ABCretail’ database.
*SQL Commands in blue 7
8. Data Definition Language
CREATE TABLE command creates an entity structure in the database by defining the following:
• Entity Name: SQL throws error for names with space character. Putting the name within square brackets [ ]
works well for names with space character.
• Field Name: Putting the name within square brackets [ ] works well for names with space character.
• Field data type: The type of data that shall be going within the Column is defined.
• Primary key: It is a field which uniquely identidies each record. It can not have Null values. There can be only
one primary key in a table which can be either on one field or more than one field.
Basic Syntax:
Create table table name (field1 datatype, field2 datatype, field3 datatype, .....fieldN datatype, PRIMARY KEY (one or
more columns ));
8
9. Ex: Let us create the following entities:
Create table Suppliers (SupplierID int primary key not null, Supplier_Type_ID int, Supplier_Name varchar(100), Supplier_Location_Manager
varchar(100), Supplier_Region varchar(75));
Create table [Store Region] (Store_Region_ID int primary key not null, Store_Region_Name varchar(100), Store_County varchar(50),
Store_State varchar(100));
Create table Store (Store_ID int primary key not null, Store_Code int, Store_Name varchar (75), Store_Region_ID int references [Store
Region] (Store_Region_ID), Store_Type varchar (50));
• The relation between Store Region and Store is based on a common field ‘Store_Region_ID’.
• It acts as a cross-reference between tables because it references the primary key of another table which in this case is Store
Region, thereby establishing a link between them.
• Such a common field providing link between two tables is known as Foreign key.
Data Definition Language [Cont..]
SUPPLIERS
SupplierID
Supplier_Type_ID
Supplier_Name
Supplier_Location_Manager
Supplier_Region
STORE REGION
Store_Region_ID
Store_Region_Name
Store_County
Store_State
STORE
Store_ID
Store_Code
Store_Name
Store_Region_ID
Store_Type
9
10. Data Definition Language [Cont..]
ALTER TABLE command is used to add, delete or modify fields in an existing entity.
• Let us add a field ‘Supplier_Contact_info’ to the Suppliers entity.
Alter table Suppliers add Supplier_Contact_Info varchar(50);
• Drop field ‘Store_County’ from Store Region.
Alter table [Store Region] drop Store_County;
• Let us modify the datatype of Store_ID from int (as defined in the previous slide) to smallint.
Alter table Store modify column Store_ID smallint;
DROP TABLE command removes the table definition and all the data for that table. Once a table is deleted then
all the information available in that table will also be lost forever.
• Suppose we want to drop Store Region
Drop table [Store Region];
10
11. Data MANIPULATION Language
Consider the following entities populated with data as shown below:
SUPPLIERS
SupplierID Supplier_Type_ID Supplier_Name Supplier_Location
_Manager
Supplier_Region
3589 58 Zai Inc David Atlantic
5871 79 Johr services Chris Ontario
8746 34 Imi Labs Bob Quebec
4812 15 Yirtel Inc Angela Ontario
9578 46 Voda services Sara Quebec
STORE
Store_ID Store_Code Store_Name Store_Region_ID Store_Type
1547 15 Monezis 258 Speciality
2624 71 Campust 358 Super market
5455 89 Leastprice 879 Discount
3879 69 Bacabus 157 Super market
6894 37 Medicas 451 Drug store
STORE REGION
Store_Region_ID Store_Region_Name Store_County Store_State
451 Atlantic Halifax Nova
Scotia
879 Quebec Montreal Quebec
358 Ontario Peterborough Ontario
157 Atlantic Charlottetown Prince
Edward
Island
258 Ontario Simcoe Ontario
*1
*2
*3
*4
*5
a
11
12. Data MANIPULATION Language [CONT..]
SELECT command is used to retrieve data from database entities.
Select SupplierID, Supplier_Type_ID, Supplier_Name from Suppliers >> This retrieves all the records for fields SupplierID,
Supplier_Type_ID and Supplier_Name from Suppliers entity.*1
Select * from Suppliers >> This gets all the records for all the fields in the entity. The result is the whole suppliers entity as
shown in previous slide.
Select top 2 * from [Store Region] >> Returns a (Refer slide 13)
SELECT command with conditional statements using WHERE, LIKE, AND, OR clauses.
Select * from Suppliers where SupplierID = 8746 >> Returns *2
Select Store_Region_ID, Store_Region_Name from [Store Region] where Store_County = ‘Peterborough’ >> Returns *3
Select * from Store where Store_Name like ‘M%’ and Store_Code = 15 >> Looks for records where Store_Name starts with
‘M’ and Store_Code is 15 and returns *4
Select * from Store where Store_Type = ‘Super market’ or Store_Code = 71 >> Looks for records where Store_Name starts
with ‘M’ or Store_Code is 15 and returns *5
12Note: * refers to slide 11
13. Data MANIPULATION Language [CONT..]
SELECT command with conditional statements using WHERE, GROUP BY, HAVING, ORDER BY clauses.
As per Store Billing Details,
Suppose we need a list of unique
bill_number with their respective
sum of [Total Amount] with the
following conditions:
1) UnitPrice > 16.00
2) Sum of [Total Amount] > 110
in descending order of Bill_Number.
Select Bill_Number, sum([Total Amount]) from [Store Billing Details]
where UnitPrice > 16
group by Bill_Number
having sum([Total Amount]) > 110
order by Bill_Number Desc
STORE BILLING DETAILS
Bill_Number ProductID UnitPrice Quantity Total
Amount
Discount Storage cost
per item
Cost price per
item
Labour
cost per
item
12345 11 20.99 5 104.95 3% 0.75 14.50 1.50
67891 25 15.49 2 30.98 2% 1.00 9.90 1.50
01112 48 121.89 1 121.89 5% 5.00 60.50 15.00
12345 67 78.45 2 156.9 5% 2.0 50.00 5.00
51617 83 35.55 3 106.65 2% 2.50 15.00 4.00
01112 57 90.99 1 90.99 5% 2.50 65.49 10.00
Bill_Number Sum(Total Amount)
12345 261.85
01112 212.88
13
14. Data MANIPULATION Language [CONT..]
INSERT INTO command is used to add new rows of data to an entity in the database.
Let us add 2 more rows
of data to
Store Billing Details
as shown in previous slide
Insert into [Store Billing Details] (Bill_Number, PoductID, UnitPrice, Quantity, [Total Amount], Discount,
[Storage cost per item], [Cost price per item], [Labour cost per item]) values
(25987, 35, 52.49, 3, 157.47, ‘5%’, 2.50, 35.50, 2.00),
(65874, 88, 35.55, 3, 106.65, ‘2%’, 2.50, 16.00, 3.00)
STORE BILLING DETAILS
Bill_Number ProductID UnitPrice Quantity Total
Amount
Discount Storage cost
per item
Cost price per
item
Labour cost
per item
12345 11 20.99 5 104.95 3% 0.75 14.50 1.50
67891 25 15.49 2 30.98 2% 1.00 9.90 1.50
01112 48 121.89 1 121.89 5% 5.00 60.50 15.00
12345 67 78.45 2 156.9 5% 2.00 50.00 5.00
51617 83 35.55 3 106.65 2% 2.50 15.00 4.00
01112 57 90.99 1 90.99 5% 2.50 65.49 10.00
25987 35 52.49 3 157.47 5% 2.50 35.50 2.00
65874 88 35.55 3 106.65 2% 2.50 16.00 3.00
14
15. Data MANIPULATION Language [CONT..]
UPDATE and DELETE commands are used to modify and delete the existing records in an entity respectively.
1) We want to change the
discount percentage of
the highlighted cell to 10%.
2) We want to keep only
those records where
quantity is less than 2.
3) Delete all records from table.
1) Update [Store Billing Details] set Discount = ’10%’ where Bill_Number = 01112 and ProductID = 48
2) Delete from [Store Billing Details] where Quantity < 2
3) Delete from [Store Billing Details]
STORE BILLING DETAILS
Bill_Number ProductID UnitPrice Quantity Total Amount Discount Storage cost
per item
Cost price
per item
Labour cost
per item
12345 11 20.99 5 104.95 3% 0.75 14.50 1.50
67891 25 15.49 2 30.98 2% 1.00 9.90 1.50
01112 48 121.89 1 121.89 5% 5.00 60.50 15.00
12345 67 78.45 2 156.9 5% 2.00 50.00 5.00
51617 83 35.55 3 106.65 2% 2.50 15.00 4.00
01112 57 90.99 1 90.99 5% 2.50 65.49 10.00
25987 35 52.49 3 157.47 5% 2.50 35.50 2.00
65874 88 35.55 3 106.65 2% 2.50 16.00 3.00
STORE BILLING DETAILS
Bill_Number ProductID UnitPrice Quantity Total Amount Discount Storage
cost per
item
Cost price
per item
Labour cost
per item
01112 48 121.89 1 121.89 5% 5.00 60.50 15.00
01112 57 90.99 1 90.99 5% 2.50 65.49 10.00
15
16. Data Control Language
Data control language commands are used by database administrator or owner of the database object
to provide/remove privileges on a database object.
GRANT command is used by database administrator to provide access or privileges on the database
objects to the users.
Grant select on Employees to user1 >> This command grants a SELECT permission on Employees
entity to user1.
REVOKE command removes user access rights or privileges to the database objects.
Revoke select on Employees from user1 >> This command will revoke a SELECT privilege on
employee entity from user1.
16
17. JOINS
In order to derive more information through entities relation with each other, we need to combine
entities based on common fields using JOIN clause.
From the above two entities, let’s say, we want to know all the store Id’s with their Name, type and state.
Select Store_ID, Store_Name, Store_Type, Store_State from [Store Region] join Store on [Store Region].Store_Region_ID = Store. Store_Region_ID
>>
17
STORE
Store_ID Store_Code Store_Name Store_Region_ID Store_Type
1547 15 Monezis 258 Speciality
2624 71 Campust 358 Super market
5455 89 Leastprice 879 Discount
3879 69 Bacabus 157 Super market
6894 37 Medicas 451 Drug store
4426 25 Medicas 554 Drug store
7413 46 Leastprice 631 Discount
STORE REGION
Store_Region_ID Store_Region_Name Store_County Store_State
451 Atlantic Halifax Nova Scotia
879 Quebec Montreal Quebec
358 Ontario Peterborough Ontario
157 Atlantic Charlottetown Prince Edward
Island
258 Ontario Simcoe Ontario
Store_ID Store_Name Store_Type Store_State
1547 Monezis Speciality Ontario
2624 Campust Super market Ontario
5455 Leastprice Discount Quebec
3879 Bacabus Super market Prince Edward
Island
6894 Medicas Drug store Nova Scotia
This reflects the common field on which the join is
based. In this case, Store_Region_ID is a common
field where it is a primary key in Store Region and a
foreign key in Store.
18. Types of JOINS
Inner Join: Returns only those set of records that match in both the entities. Inner Join is same
as join, as explained in the previous slide.
Left Join: Returns all rows from the left entity, even if there are no matches in the right entity.
Select Store_ID, Store_State from Store left join [Store Region] on Store.Store_Region_ID = [Store Region].Store_Region_ID
>>
Right Join: Returns all rows from the right entity, even if there are no matches in the left entity.
Select Store_ID, Store_State from Store right join [Store Region] on Store.Store_Region_ID = [Store Region].Store_Region_ID
Full Join: Returns all the records from both the entities. It is a combination of the result of both left
join and right join.
Select Store_ID, Store_State from Store full join [Store Region] on Store.Store_Region_ID = [Store Region].Store_Region_ID
18
Store_ID Store_State
1547 Ontario
2624 Ontario
5455 Quebec
3879 Prince Edward Island
6894 Nova Scotia
4426 Null
7413 Null
Store_ID Store_State
6894 Nova Scotia
5455 Quebec
2624 Ontario
3879 Prince Edward Island
1547 Ontario
19. Why do we use SQL when we have Excel?
• Considering the huge database of ABC Companies Limited (refer slide 4), with some entities like
store billing going up to millions of records, Excel won’t last a few hours before it comes unusable.
• Let’s say we want to know the number of units of a particular product broken down by store and
how many of those customers are end users. In a SQL database, that’s a fairly easy query to write
and we will retrieve data in seconds.
Doing the same in excel might be arduous and time consuming.
• SQL separates analysis from data. When using SQL, data is stored separately from analysis.
That saves us from emailing large excel files. Instead send small text files having the instructions
for analysis.
Also saves from having to manage file versions or risk corrupting the data.
19
20. APPENDIX
DATATYPES
20
DATA TYPE FROM TO
bigint -9,223,372,036,854,775,808 9,223,372,036,854,775,807
int -2,147,483,648 2,147,483,647
smallint -32,768 32,767
tinyint 0 255
bit 0 1
decimal -10^38+1 10^38-1
numeric -10^38+1 10^38-1
money -922,337,203,685,477.5808 +922,337,203,685,477.5807
smallmoney -214,748.3648 +214,748.3647
Exact Numeric Data Types
21. APPENDIX
DATATYPES
21
DATA TYPE Description
char Maximum length of 8,000 characters.(Fixed length non-Unicode characters)
varchar Maximum of 8,000 characters.(Variable length non-Unicode data)
varchar(max) Maximum length of 231 characters. Variable length non-Unicode data (SQL Server 2005 only).
text Variable length non-Unicode data with a maximum length of 2,147,483,647 characters.
Character Strings Data Types
DATA TYPE Description
nchar Maximum length of 4,000 characters.(Fixed length Unicode)
nvarchar Maximum of 4,000 characters.(Variable length Unicode)
nvarchar(max) Maximum length of 231 characters. Variable length Unicode (SQL Server 2005 only).
ntext Maximum length of 1,073,741,823 characters. (Variable length Unicode)
Unicode Character Strings Data Types
22. 22
All the commands (Highlighted in blue) work for MS SQL Server.
Thank You
Created by Pavani Ganti