Cover | Table of Contents | Colophon
sac.exe command-line utility imports Microsoft SQL Server 2005 surface settings so that you can apply them to other SQL Server instances. The utility is in the C:\Program Files\Microsoft SQL Server\90\Shared directory (assuming that you installed SQL Server to the default directory).dta.exe.profiler90.exe.|
Utility
|
Description
|
|---|---|
|
sqlcmd
|
Executes T-SQL statements, system procedures, and script files from the command prompt. The
sqlcmd utility is described further later in this section. |
|
sqlwb
|
Launches SQL Server Management Studio from the command prompt.
|
|
profiler90
|
Launches SQL Server Profiler from the command prompt.
|
|
dta
|
Launches Database Engine Tuning Advisor from the command prompt.
|
|
dtexec
|
Used to configure and execute an SSIS package loaded from a database, the SSIS package store, or the file system.
|
|
dtutil
|
Used to manage and verify existence of an SSIS package stored in the SQL Server msdb database, the SSIS package store, or the file system.
|
|
tablediff
|
Used to compare the data in two tables for nonconvergence.
|
xml
data type and large value
data types. The xml data type supports storing XML documents and fragments in the database. Large value data types—varchar(max), nvarchar(max), and varbinary(max)—extend the storage capacity of varchar, nvarchar, and varbinary data types up to 231 bytes of data.xml data type stores XML documents and fragments natively as a column, variable, parameter, or function return type. A schema can be associated with an xml data type to validate each instance of the type—the XML instance is then typed. An XML instance without a schema is untyped. xml data types can be manipulated using XQuery and XML DML. Columns of xml data type can be indexed.varchar, nvarchar, and varbinary variable-length data types:xml
data type and large value
data types. The xml data type supports storing XML documents and fragments in the database. Large value data types—varchar(max), nvarchar(max), and varbinary(max)—extend the storage capacity of varchar, nvarchar, and varbinary data types up to 231 bytes of data.xml data type stores XML documents and fragments natively as a column, variable, parameter, or function return type. A schema can be associated with an xml data type to validate each instance of the type—the XML instance is then typed. An XML instance without a schema is untyped. xml data types can be manipulated using XQuery and XML DML. Columns of xml data type can be indexed.varchar, nvarchar, and varbinary variable-length data types:varchar(max), nvarchar(max), and varbinary(max). You use the max specifier to extend the storage capability of varchar, nvarchar, and varbinary data types to 231 bytes in the varchar and varbinary data types and to 2TOP clause supports using an expression to specify the number of rows or percent of rows returned in the result set.TABLESAMPLE clause returns a random sample of rows from the result set.OUTPUT clause returns a result set containing the rows affected by an INSERT, UPDATE, or DELETE statement.SOME, ANY, and ALL operators compare the values in a column with a scalar value.PIVOT operator rotates a table, turning unique values in column rows into multiple columns in the result set, while the new UNPIVOT operator turns multiple columns in a result set into rows.APPLY operator invokes a table-valued function for each row in a result set.EXECUTE AS clause defines the user execution context of T-SQL statements.ROW_NUMBER( ), DENSE_RANK( ), and NTILE( ) ranking functions are added to the RANK function that exists in SQL Server 2000.TRY...CATCH blocks.TOP clause limits the number of rows returned in a result set. SQL Server 2005 enhances the TOP clause to allow an expression to be used as the argument to the TOP clause instead of just a constant as was the case in SQL Server 2000. The TOP clause can be used in SELECT, INSERT, UPDATE, and DELETE statements.INSERT, UPDATE, or DELETE. SQL Server 2005 introduces Data Definition Language (DDL) triggers that fire in response to DDL statements that change the database schema or database server. These statements include CREATE, ALTER, DROP, GRANT, DENY, and REVOKE. DDL triggers
are typically used for auditing and logging.
CREATE TRIGGER trigger_name
ON { ALL SERVER | DATABASE }
[ WITH <ddl_trigger_option> [ ...,n ] ]
{ FOR | AFTER } { event_type | event_group } [ ,...n ]
AS { sql_statement [ ...n ] | EXTERNAL NAME < method specifier > }
[ ; ]
<ddl_trigger_option> ::=
[ ENCRYPTION ]
[ EXECUTE AS Clause ]
<method_specifier> ::=
assembly_name.class_name.method_name
ON { ALL SERVER | DATABASE }
ALL SERVER fire whenever event_type or event_group happens anywhere in the current server. You must have at least CONTROL SERVER permission on the server to create a DDL trigger with server scope.DATABASE fire whenever event_type or event_group occurs in the current database.WITH ENCRYPTION clause encrypts the CREATE TRIGGER statement body and prevents it from being accessed through catalog views or from being published as part of SQL Server replication.EXECUTE AS clause specifies the security context under which the trigger is executed.SELECT statement in the same way as any other database view and return data as standard result sets. Catalog views are often joined in queries to retrieve complex metadata.AdventureWorks database. One record is returned in the result set for each table.
SELECT * FROM sys.tables
sp_configure system stored procedure to enable CLR integration, as shown here:
sp_configure 'clr enabled', 1
GO
RECONFIGURE
GO
clr enabled server configuration option specifies whether .NET assemblies can be run by SQL Server (0 = do not allow; 1 = allow). The change takes effect immediately after sp_configure and reconfigure are executed—the server does not need to be restarted.ALTER SETTINGS permissions at the server level to enable CLR integration.System.Data.dll—part of the base class library of the .NET Framework and located in both the Global Assembly Cache (GAC)
and in the <windir>\Microsoft.NET\Framework\<version> directory. The key namespaces in this assembly are described in Table 4-2.|
System.Data.dll namespaces
|
Description
|
|---|---|
System.Data
|
Classes that comprise the ADO.NET architecture
|
System.Data.Sql
|
Classes that support SQL Server 2005-specific functionality
|
Microsoft.SqlServer.Server
|
Classes that support .NET CLR functionality inside SQL Server CLR routines—user-defined functions (UDFs), stored procedures, UDA functions, UDTs, and triggers
|
System.Data.SqlTypes
|
Classes that support native SQL Server data types
|
System.Data.SqlClient
|
.NET Frameworks data provider for SQL Server
|
|
Database object
|
.NET Framework assembly type
|
Description
|
|---|---|---|
|
Scalar-valued function
|
Public static method
|
A UDF that returns a single value.
|
|
Table-valued function
|
Public static method
|
A UDF that returns a table as the result set.
|
|
Stored procedure
|
Public static method
|
A routine that returns tabular result sets and messages to the client, invokes DDL and DML statements, and returns output parameters.
|
|
User-defined aggregate function
|
Class or structure
|
A UDA function that operates on values in a set of rows and returns a scalar.
|
|
User-defined type
|
Class or structure
|
Complex data types complete with methods that extend the scalar type system in SQL Server.
|
|
Trigger (DML and DDL)
|
HelloWorld, specify the location, and click OK.
HelloWorld project and select Add → Stored Procedure from the context menu, as shown in Figure 4-3.
HelloWorldStoredProcedure.cs and click Add.HelloWorldStoredProcedure( ) method in HelloWorldStoredProcedure.cs:
SqlContext.Pipe.Send("Hello world.\n");
|
Scope
|
DDL statement
|
New T-SQL statement
|
Description
|
|---|---|---|---|
|
.NET Framework assembly
|
CREATE ASSEMBLY
|
Yes
|
Loads assembly into SQL Server.
|
ALTER ASSEMBLY
|
Yes
|
Changes a loaded assembly.
| |
DROP ASSEMBLY
|
Yes
|
Unloads an assembly from SQL Server.
| |
|
User-defined aggregate function
|
CREATE AGGREGATE
|
Yes
|
Creates a UDA function in a SQL Server database from a UDA function implemented as a class in a .NET Framework assembly.
The assembly containing the class must first be registered in SQL Server with the |