Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Module 1: Getting Started with Databases and Transact-SQL in SQL Server 2008
Overview of SQL Server 2008 Overview of SQL Server Databases
OLE DB Components
OLE DB Components Business Logic
Application Server
SQL Server An interface to provide management for Configuration Manager SQL services, protocols, and client aliases
A GUI tool to profile and trace the Database Engine and Analysis Services An application to create an optimal sets of indexes, indexed views, and partitions An IDE for creating Analysis Services, Reporting Services, and Integration Services solutions
Description
Relational
Engine
Storage
Engine
SQLOS
Order Details OrderID ProductID UnitPrice Quantity Products ProductID ProductName SupplierID
ShippedDate
ShipVia Freight
UnitPrice UnitsInStock
Discontinued
What Is Normalization?
The process for removing redundant data from a database Benefits
Accelerates sorting and indexing Allows more clustered indexes Helps UPDATE performance
Disadvantages
Increase in tables to join Insertion of code in tables Slower data retrieval Difficulty in data model query
Product2
Address
PostCode City
Enable fast retrieval, built from one or more columns in table or view
Execute a batch of SQL code when an insert, update or delete command is executed against a specific table
Triggers
Procedures
1
2 3
The number and attributes of the columns in the result set The tables from which the result set data is retrieved The conditions the rows in the source tables must meet The sequence which the rows of the result set are ordered
SELECT ProductID, Name, ListPrice FROM Production.Product WHERE ListPrice > $40 ORDER BY ListPrice ASC
Operators
+, -, *, /, % Vacation + SickLeave AS 'Total PTO' = SET @MyCounter = 1 =, <, >, <>, !, >=, <= IF (@MyProduct <> 0) AND, OR, NOT WHERE Department = Sales' AND (Shift = 'Evening' OR Shift = 'Night') + SELECT LastName + ', ' + FirstName AS Moniker
Logical operators
String concatenation
operator
Notes
Return objects that can be used as table references
DECLARE @local_variable as <data_type> declare @food varchar(20) set @food = 'ice cream' WHERE Description = @food
Control-of-flow Statements
These are the control-of-flow keywords:
BEGIN...END GOTO IF...ELSE RETURN BREAK CONTINUE WHILE WAITFOR
IF @cost <= @compareprice BEGIN PRINT 'These products can be purchased for less than $'+RTRIM(CAST(@compareprice AS varchar(20)))+'.' END ELSE PRINT 'The prices for all products in this category exceed $'+ RTRIM(CAST(@compareprice AS varchar(20)))+'. GO
RAISERROR RAISERROR (N'This is message %s %d.', -- Message text. 10, -- Severity, 1, -- State, N'number', -- First argument. 5); -- Second argument. -- The message text returned is: This is message number 5. GO
/* This is a comment */
The double dash comments to the end of line
--This is a comment
Description
Used for interactive creation of T-SQL scripts To access, configure, manage, and create
Management Studio
SQLCMD
PowerShell
A solution includes projects and files that define the solution A project is a set of files, plus related metadata When you create a project, a solution is created to contain it
window
Logon information
Lab Scenario
You are the database administrator of Adventure Works.
The Human Resources department requires that you generate several reports by using SQL Server 2008. You need to generate reports with a list of employee addresses sorted by departments or a list of addresses of employees residing in the United States. You also need to analyze the details of the newly hired employees by using a database diagram in SQL Server Management Studio.
To do this, you will explore and execute queries in SQL
Server Management Studio, generate reports from the AdventureWorks database, and examine the database diagram in SQL Server Management Studio.
Lab Review
Why would we execute a T-SQL command using sqlcmd? What tools did we use in the lab to query the database?
databases?
Tools