Beginning SQL: Microsoft SQL Server Introductory SQL
Beginning SQL: Microsoft SQL Server Introductory SQL
Beginning SQL
Microsoft SQL Server Introductory SQL
Presented by:
Prepared by:
Jeremy Kingry
eBECS LTD.
Overview
• What is SQL
• SQL Server Management Studio (SSMS)
• Standard SQL Commands (SELECT, INSERT,
UPDATE, DELETE)
• Common SQL Functions
What is SQL
• Structured Query Language (SQL)
• A special-purpose programming language
designed for managing data held in a relational
database management system (eg SQL Server)
• Standard of the American National Standards
Institute (ANSI) and International Organization
for Standardization (ISO)
SQL Server Management Studio
• Standard SQL Interface
• Hierarchical Database Navigation
• Database Objects
• SQL Database Table
• SQL Database View
SSMS Overview
SQL Commands
SELECT select_list
[ FROM table_source ]
[ WHERE search_condition ]
[ GROUP BY group_by_expression ]
[ ORDER BY order_expression [ ASC | DESC ] ]
SELECT Demo
--How many customer accounts per salesperson?
SELECT S.SLPRSNID, S.SLPRSNFN, S.SPRSNSLN,
COUNT(R.CUSTNMBR)
FROM RM00301 S
INNER JOIN RM00101 R ON S.SLPRSNID = R.SLPRSNID
GROUP BY S.SLPRSNID, S.SLPRSNFN, S.SPRSNSLN
ORDER BY S.SLPRSNFN, S.SPRSNSLN
INSERT
begin tran
UPDATE SY00500
SET BCHSTTUS = 0, MKDTOPST = 0
WHERE BACHNUMB= '' --update batch number
commit
--rollback
DELETE
DELETE
FROM table
[ WHERE search condition ]
DELETE Demo
--Clear GP Locks
Delete DYNAMICS..SY00800
Delete DYNAMICS..SY00801
Delete DYNAMICS..ACTIVITY
Delete TEMPDB..DEX_LOCK
Delete TEMPDB..DEX_SESSION
COMMON SQL FUNCTIONS
TOP
COUNT(*)
MIN, MAX, AVG
CONCATENATION
IS NULL
COMMON SQL FUNCTIONS Demo
--Quantity sold for year by customer and item
SELECT SOP30200.CUSTNMBR, SOP30300.ITEMNMBR, SOP30300.ITEMDESC,
SUM(SOP30300.QUANTITY) AS 'QTY'
FROM SOP30200
inner Join SOP30300 on SOP30200.SOPNUMBE = SOP30300.SOPNUMBE
WHERE Year(SOP30200.docdate) = '2017'
AND SOP30200.SOPTYPE = 3
GROUP BY SOP30200.CUSTNMBR, SOP30300.ITEMNMBR, SOP30300.ITEMDESC
Questions
RESOURCES