Whats New in SQL Server 2005
Whats New in SQL Server 2005
Table of Contents
What's new in SQL Server 2005 ............................................................................................. 1
Exercise 1 Data Management in SQL Server 2005...............................................................................................2
Exercise 2 Transact-SQL Enhancements: PIVOT and UNPIVOT .....................................................................5
Exercise 3 Transact-SQL Enhancements: TRY/CATCH .....................................................................................7
What's new in SQL Server 2005
Page 1 of 9
What's new in SQL Server 2005
Exercise 1
Data Management in SQL Server 2005
Scenario
The SQL Server Management Studio simplifies management by provided one integrated management console to
monitor and manage the SQL Server relational database. This exercise briefly introduces this powerful tool.
Page 2 of 9
What's new in SQL Server 2005
Tasks Detailed Steps
Management Studio provided us with the basis for modifying the trigger.
k. Right-click the Person.Contact node and click Open Table.
l. Close the Properties pane.
The SQL Server Management Studio provides full editable tables as well as multiple
query windows.
m. Scroll through the data.
n. Click on Person.Contact.
o. Click New Query.
p. In the new query pane, type
SELECT * from Person.Contact
WHERE FirstName=’Gustavo’
q. Click the check button next to the Execute button.
r. Click the Execute button.
s. Collapse the Tables node.
2. Database security The SQL Server Management console allows you to view and edit users and roles
roles through the associated with a database.
Management Studio. a. Click to expand the AdventureWorks | Security node.
b. Click to expand the Users node.
c. Click to expand the Roles node.
d. Under the Users node, right-click guest and click Properties.
Here, we are able to edit database permission that a user has.
e. Close the Database User – guest window.
f. Collapse the AdventureWorks node.
3. Groups and a. Click to expand the Security node.
permissions for SQL In the SQL Server security section, administrators can edit the Logins and Server
Server. Roles for the entire SQL Server system.
b. Click to expand the Management node.
The SQL Server Management Studio brings together the many aspects of SQL Server
management. Here, adminstrators can monitors SQL Server Logs, monitor activity
and undertake other tasks related to Server management.
4. Multiple a. In the Object Explorer, Click Connect | Database Engine.
Connections. b. Click the Server Name dropdown
c. Click <Browse for more>.
Microsoft SQL Server Management Studio allows you to connect to multiple
registered servers at once. On this machine, there is only one machine and one
registered server.
d. Click Cancel.
e. Click Cancel.
Page 3 of 9
What's new in SQL Server 2005
Tasks Detailed Steps
5. SQL Server If you are familiar with Visual Studio 2005, you will be familiar with the concept of
Management Studio projects. Microsoft SQL Server Management Studio supports projects, allowing you to
projects. save all of your queries, views, and connections in one easy to access project.
a. Click File | New | Project.
b. Click OK.
c. If prompted to save, click No.
d. Note the new pane, the Solution Explorer.
e. In the Solution Explorer, right-click Connections, and click New Connection.
f. Click OK.
g. In the Solution Explorer, right-click Queries, and click New Query.
h. Click Connect.
i. In the VSTS.master –SQLQuery1.sql pane, type the same query as before:
USE AdventureWorks
SELECT * from Person.Contact
WHERE FirstName=’Gustavo’
j. Click File | Close Solution.
k. Click Yes.
l. Click File | Open | Project/Solution.
m. Double-click the SQL Server Scripts1 directory.
n. Select SQL Server Scripts1.ssmssln and click Open.
6. Error checking. The SQL Server Management Studio also allows you to easily find errors in your
scripts.
a. In the Object Explorer, expand the VSTS | Databases | AdventureWorks |
Programmability | Stored Procedures node.
b. Right-click on dbo.uspGetBillOfMaterials and click Modify.
c. Minimize the Solution Explorer, by clicking the Thumb-Tack icon, for more
viewing room if necessary.
d. Remove the AND from the line
AND @CheckDate <= ISNULL(b.[EndDate], @CheckDate)
e. Click the Parse button. (The button with the check icon)
f. Double-click on the red error in the Results pane.
When double-clicking on a scripting error, SQL Server Management Studio will direct
you to the line containing the error.
g. Correct the error by returning the AND and click Parse again.
h. Minimize the SQL Server Management Studio.
Page 4 of 9
What's new in SQL Server 2005
Exercise 2
Transact-SQL Enhancements: PIVOT and UNPIVOT
Scenario
In this exercise, we will see how the new PIVOT and UNPIVOT commands can be used to rotate data around a
column.
Page 5 of 9
What's new in SQL Server 2005
Tasks Detailed Steps
FOR [FiscalYear]
IN ([2002], [2003], [2004])
) AS pvt;
e. Note especially the PIVOT command at the end of the view.
This is creating a view from several tables, and then pivoting the data around the
years 2002, 2003 and 2004. This type of PIVOT operation is extremely useful when
displaying data that can be logically grouped by multiple different columns.
f. Right-click Sales.vSalesPersonSalesByFiscalYear and click Open View.
g. Note how the data is pivoted around the column Fiscal Year.
The UNPIVOT operator performs an opposite operation to PIVOT, rotating columns
into rows. It narrows the input table expression based on a pivot column. These new
recursive queries provide a way to reshape data.
Page 6 of 9
What's new in SQL Server 2005
Exercise 3
Transact-SQL Enhancements: TRY/CATCH
Scenario
In this exercise, we discuss the new TRY/CATCH feature of Transact-SQL and examine a stored procedure that
uses it.
INSERT [dbo].[ErrorLog]
(
[UserName],
[ErrorNumber],
[ErrorSeverity],
[ErrorState],
[ErrorProcedure],
[ErrorLine],
Page 7 of 9
What's new in SQL Server 2005
Tasks Detailed Steps
[ErrorMessage]
)
VALUES
(
CONVERT(sysname, CURRENT_USER),
ERROR_NUMBER(),
ERROR_SEVERITY(),
ERROR_STATE(),
ERROR_PROCEDURE(),
ERROR_LINE(),
ERROR_MESSAGE()
);
Of course, these three examples are just scratching the surface of the new
functionality provided in SQL Server 2005. SQL Server 2005 provides the
technologies and capabilities that organizations and database administrators count
on. The spectrum of new and enhanced functionality that affect database
administration is immense. For more information on the new functionality in SQL
2005, visit the Microsoft SQL Server 2005 web site, or look for other Virtual Labs
using SQL Server 2005.
Page 8 of 9
What's new in SQL Server 2005
Page 9 of 9