Download presentation
Presentation is loading. Please wait.
Published byCamron Roberts Modified over 8 years ago
1
Brian Alderman | MCT, CEO / Founder of MicroTechPoint Pete Harris | Microsoft Senior Content Publisher
2
Meet Brian Alderman | @brianalderman Chief Executive Office, Founder MicroTechPoint Industry-recognized consultant Noted author and conference speaker Brian’s expertise and designs range across Microsoft operating systems More than 25 years of industry experience Brian has been focused on helping IT Pros and Database Administrators (DBAs) better understand core Microsoft technologies for over 25 years. A frequent presenter at SharePoint Conferences around the world, he has authored or contributed to several SharePoint, SQL Server, and other technical books, and is a MCSE, MCT, and MCITP: SharePoint and SQL Server Administrator. Brian has a BS and MS in Computer Information Systems where he graduated summa cum laude from Regis University of Colorado Springs and lives in Scottsdale, AZ where he enjoys playing golf year round and traveling around the world. LinkedIn /brianalderman Blog http://brianalderman.wordpress.com
3
Meet Pete Harris | @SQLPete Content Development Manager in Microsoft’s Learning Experiences team Focuses on SQL Server and Web training With Microsoft since 1995 Part of the first team of developer training folks in the post-Microsoft University era Has built a variety of content and spoken to customers all over the world
4
Course Modules Database Fundamentals 01 | Introducing core database concepts (50 minutes) Define databases, example of relational database tables, and introduce common database terminology 02 | Relational Concepts (50 minutes) Normalization, referential integrity, and constraints 03 | Creating databases and database objects (50 minutes) Data types, database objects, DDL statements, and creating scripts 04 | Using DML statements (50 minutes) DML statements, using the SELECT statement; using INSERT, UPDATE, and DELETE to manage data; indexes and triggers 05 | SQL Server Administration Fundamentals (50 minutes) SQL Server security; securing database and objects; performing database backups and database restores
5
04 | Using DML Statements Brian Alderman | MCT, CEO / Founder of MicroTechPoint Pete Harris | Microsoft Senior Content Publisher
6
Introducing DML statements Using the SELECT statement Modifying data using DML statements Indexes and triggers Module Overview
7
DML Statements
8
SELECT – retrieve data INSERT – add data UPDATE – modify data DELETE – remove data BULK INSERT – Import a data file Common DML statements
9
The SELECT statement
10
Using the basic SELECT statement The SELECT statement is used to retrieve rows and columns from a table SELECT * FROM tablename The SELECT statement requires the name of the table and either the * (retrieves all columns) or specific column names To limit the number of rows returned you can include the WHERE clause in the SELECT statement
11
Sample SELECT statement SELECT BusinessEntityID, JobTitle, Gender FROM HumanResources.Employee WHERE BusinessEntityID <= 50 Returns the following results: BusinessEntityIDTitle Gender -------------------------------- --------- 1Chief Executive Officer M 2Vice President of Engineering F 3Engineering Manager M 4Senior Tool Designer M
12
Multiple WHERE clauses You can combine several WHERE clauses in one query statement to create more specific queries. SELECT BusinessEntityID, Jobtitle, VacationHours FROM HumanResources.Employee WHERE JobTitle = ‘Design Engineer’ AND gender = ‘F’ AND HireDate >= ‘2000-JAN-01’ SELECT BusinessEntityID, Jobtitle, VacationHours FROM HumanResources.Employee WHERE VacationHours > 80 OR BusinessEntityID <= 50
13
Using the BETWEEN clause Retrieving rows within a date range using the BETWEEN clause SELECT BusinessEntityID, Jobtitle, VacationHours FROM HumanResources.Employee WHERE VacationHours BETWEEN 75 AND 100
14
Sorting the result set using ORDER By Sorting the result set by using the ORDER BY to specify what field to sort by. SELECT BusinessEntityID, Jobtitle, VacationHours FROM HumanResources.Employee WHERE VacationHours BETWEEN 75 AND 100 ORDER BY VacationHours You can sort in descending order by using the DESC clause. SELECT BusinessEntityID, Jobtitle, VacationHours FROM HumanResources.Employee WHERE VacationHours BETWEEN 75 AND 100 ORDER BY VacationHours DESC
15
Using the NOT clause Write a query to return data that specifies what you don’t want returned SELECT BusinessEntityID, Jobtitle, Gender FROM HumanResources.Employee WHERE NOT Gender = ‘M’
16
UNION clause The UNION clause allows you to combine the rows returned from multiple SELECT statements into a single result set SELECT BusinessEntityID, Jobtitle, HireDate FROM HumanResources.Employee WHERE JobTitle = 'Design Engineer' UNION SELECT BusinessEntityID, Jobtitle, HireDate FROM HumanResources.Employee WHERE HireDate BETWEEN '2005-01-01' AND '2005- 12-31'
17
EXCEPT and INTERSECT clauses The EXCEPT clause returns distinct values from the left query that are not found on the right query SELECT ProductID FROM Production.Product EXCEPT SELECT ProductID FROM Production.WorkOrder ; The INTERSECT clause returns any distinct values returned by both the query on the left and right sides of intersect operand SELECT ProductID FROM Production.Product INTERSECT SELECT ProductID FROM Production.WorkOrder ;
18
JOIN clause The JOIN clause allows you to combine related data from multiple tables into one result set INNER JOINS uses a comparison operator to match rows from two tables based on values in a common column that exists in both tables OUTER JOINS (left, right, or full) includes rows from one or both tables even if they don’t have matching values CROSS JOINS return all rows from the left table with all rows from the right table. WHERE conditions should always be included.
19
Aggregate sample SQL Server provides aggregate functions to assist with the summarization of large volumes of data SELECT COUNT (DISTINCT SalesOrderID) AS UniqueOrders, AVG(UnitPrice) AS Avg_UnitPrice, MIN(OrderQty)AS Min_OrderQty, MAX(LineTotal) AS Max_LineTotal FROM Sales.SalesOrderDetail; Demo query generator
20
Using the SELECT Statement Demo
21
Inserting data You can add a new row to a table using the INSERT statement INSERT INTO Production.UnitMeasure VALUES (N'FT', N'Feet', '20080414') You can add multiple rows to a table using the following INSERT statement INSERT INTO Production.UnitMeasure VALUES (N'FT2', N'Square Feet ', '20080923'), (N'Y', N'Yards', '20080923'), (N'Y3', N'Cubic Yards', '20080923' BULK INSERT can be used to import a data file into a table with a user- specified format.
22
Update statement The UPDATE statement is used to modify the data that is already stored in a table UPDATE Sales.SalesPerson SET Bonus = 6000, CommissionPct =.10, SalesQuota = NULL WHERE sales.SalesPerson.BusinessEntityID = 289
23
DELETE statement The DELETE statement is used to delete rows from a table DELETE FROM Production.UnitMeasure WHERE Production.UnitMeasure.Name = ‘Feet’ A DELETE statement without a WHERE clause will cause all rows to be deleted DELETE FROM Sales.SalesPersonQuotaHistory;
24
Modifying data using DML statements Demo
25
Indexes and triggers
26
SQL Server indexes Indexes allow you to speed up the retrieval of data stored within a table or view The SQL Server query optimizer evaluates each method for retrieving the data and selects the most efficient method which may be a table scan or using one or more indexes if they exist. The most commonly used indexes include clustered nonclustered unique
27
Creating a DML trigger Triggers are used to enforce business rules when data is modified This DML trigger displays a message to the user when they try to add or change data in the customer table CREATE TRIGGER Reminder1 ON Sales.Customer AFTER INSERT, UPDATE AS RAISERROR ('Notify Customer Relations', 16, 10); GO
28
Summary The SELECT statement is use to retrieve data from one or more tables stored in a database The SELECT command must indicate what columns and what table you want to retrieve data from when executing the query. Optionally the SELECT statement can include the WHERE clause to define the conditions used to determine what rows will be returned
29
Summary Other arguments that can be used to control what data is returned include; BETWEEN NOT UNION EXCEPT INTERSECT JOIN (INNER, OUTER, CROSS)
30
Summary DML commands that can be used to manage table and view data include INSERT BULK INSERT UPDATE DELETE Indexes are used to speed up the retrieval of data from tables and views Triggers are used to enforce business rules when data is modified
31
©2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Office, Azure, System Center, Dynamics and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.