24
Application development using Microsoft SQL Server 2000 Peter Ty Peter Ty Developer Evangelist Developer Evangelist .NET and Developer Group .NET and Developer Group

Application development using Microsoft SQL Server 2000

Embed Size (px)

Citation preview

Page 1: Application development using Microsoft SQL Server 2000

Application development using Microsoft SQL Server 2000

Peter TyPeter Ty

Developer EvangelistDeveloper Evangelist

.NET and Developer Group.NET and Developer Group

Page 2: Application development using Microsoft SQL Server 2000

SQL Server 2000 SQL Server 2000

Application Migration Application Migration Engine EnhancementEngine Enhancement XML SupportXML Support Multiple InstancesMultiple Instances

Page 3: Application development using Microsoft SQL Server 2000

Application MigrationApplication Migration Avoid accessing System TablesAvoid accessing System Tables SQL-SCM API removedSQL-SCM API removed SQL6.5: SQL-DMO, Tasks and SQL6.5: SQL-DMO, Tasks and

replication: objects changedreplication: objects changed SQL6.5: DUMP/LOAD: uses SQL6.5: DUMP/LOAD: uses

BACKUP/RESTOREBACKUP/RESTORE Setting Backward Compatibility Setting Backward Compatibility

level: level: sp_dbcmptlevel (60, 65, 70, sp_dbcmptlevel (60, 65, 70, 80)80)

Uses ADO/ADO.NETUses ADO/ADO.NET

Page 4: Application development using Microsoft SQL Server 2000

Automatic Cascading of Deletes and Automatic Cascading of Deletes and Updates from PK to FK TablesUpdates from PK to FK Tables

ANSI Standard Restrict and Cascade ANSI Standard Restrict and Cascade SemanticsSemantics

CREATE TABLE country ( country_name NVARCHAR(75) NOT NULL PRIMARY KEY )

CREATE TABLE employee ( employee_name NVARCHAR(75) NOT NULL, country NVARCHAR(75) NOT NULL REFERENCES country ON UPDATE CASCADE ON DELETE NO ACTION, passport_number VARCHAR(25) NOT NULL, PRIMARY KEY (nationality, passport_number))

Engine EnhancementsEngine EnhancementsCascaded DRICascaded DRI

Page 5: Application development using Microsoft SQL Server 2000

Engine EnhancementsEngine Enhancements User-Defined FunctionsUser-Defined Functions Multi-Statement T-SQL RoutinesMulti-Statement T-SQL Routines Scalar-ValuedScalar-Valued

Select f(c1) …Select f(c1) … Select … where f2(c2)Select … where f2(c2) Usable in any expression (Order By, Group By..)Usable in any expression (Order By, Group By..)

Table-Valued (Also Called Relational) Table-Valued (Also Called Relational) Select c1 from f(arg)…Select c1 from f(arg)…

Strongly Typed Input Args with Return Value Strongly Typed Input Args with Return Value No output parametersNo output parameters

Inline Relational FunctionsInline Relational Functions Effectively a parameterized viewEffectively a parameterized view

Page 6: Application development using Microsoft SQL Server 2000

Engine Enhancements Engine Enhancements Scalar UDF ExampleScalar UDF ExampleCREATE FUNCTION ExtractNamePart(@InName varchar(100),

@part tinyint)RETURNS varchar(30) ASBEGIN

DECLARE @offset tinyintSET @offset = charindex(' ', @InName)

RETURN CASE @part WHEN 1 THEN substring(@InName, 1, @offset-1) WHEN 2 THEN substring(@InName,@offset+1,

len(@InName)) ELSE NULL

ENDEND

Page 7: Application development using Microsoft SQL Server 2000

Engine Enhancements Engine Enhancements Column-Level CollationsColumn-Level Collations

Multilingual Applications, Multilingual Applications, Application Hosting, and Server Application Hosting, and Server ConsolidationConsolidation

Per-Database CollationsPer-Database Collations Multiple apps with different collationsMultiple apps with different collations

Per-Column CollationsPer-Column Collations Deeper multi-lingual applicationsDeeper multi-lingual applications

Attach and Restore Databases with Attach and Restore Databases with Different Collations from ServerDifferent Collations from Server

Full Backward-CompatibilityFull Backward-Compatibility

Page 8: Application development using Microsoft SQL Server 2000

Engine Enhancements Engine Enhancements Instead-Of TriggersInstead-Of Triggers

Trigger Executed Instead of Trigger Executed Instead of INSERT, DELETE, or UPDATE INSERT, DELETE, or UPDATE OperationOperation

ApplicationApplication Allows any view to be updateableAllows any view to be updateable Implement before triggersImplement before triggers

Supported on View or TableSupported on View or Table Inserted / Deleted Tables AvailableInserted / Deleted Tables Available

Page 9: Application development using Microsoft SQL Server 2000

Engine Enhancements Engine Enhancements Instead-Of Trigger ExampleInstead-Of Trigger Example

Updateable Partitioned ViewUpdateable Partitioned View Partitioning column: RegionPartitioning column: Region

CREATE VIEW CustomersAll AS

SELECT CustomerID, CompanyName, Address, Region

FROM CustomerEast

UNION ALL

SELECT CustomerID, CompanyName, Address, Region

FROM CustomerCentral

UNION ALL

SELECT CustomerID, CompanyName, Address, Region

FROM CustomerWest

Page 10: Application development using Microsoft SQL Server 2000

Engine Enhancements Engine Enhancements Instead-Of Trigger ExampleInstead-Of Trigger ExampleCREATE TRIGGER IO_Trig_INS_CustomersAll ON CustomersAllINSTEAD OF INSERT ASBEGIN

INSERT INTO CustomersEast SELECT CustomerID,CompanyName,Address,RegionFROM inserted WHERE Region = ‘East’

INSERT INTO CustomersCentral SELECT CustomerID, CompanyName, Address,RegionFROM inserted WHERE Region = ‘Central’

INSERT INTO CustomersWest SELECT CustomerID, CompanyName, Address,RegionFROM inserted WHERE Region = ‘West’

END --trigger action

Page 11: Application development using Microsoft SQL Server 2000

Engine Enhancements Engine Enhancements New Data TypesNew Data Types TableTable

Return type for table-valued UDFsReturn type for table-valued UDFs Allows easier programming of iterative Allows easier programming of iterative

operationsoperations

BigIntBigInt 8-byte integer8-byte integer

SQL_VariantSQL_Variant Can store any base type (except LOB)Can store any base type (except LOB) Can be used to implement an open Can be used to implement an open

schemaschema

Page 12: Application development using Microsoft SQL Server 2000

Engine Enhancements Engine Enhancements Indexes on Computed ColumnsIndexes on Computed Columns Computed Columns Were Computed Columns Were

Introduced in SQL Server 7.0Introduced in SQL Server 7.0 SQL Server 2000 Allows You to SQL Server 2000 Allows You to

Create Indexes on Computed Create Indexes on Computed ColumnsColumns The expression defining the computed The expression defining the computed

column must be DETERMINISTICcolumn must be DETERMINISTIC Certain SET options must be specified Certain SET options must be specified

Page 13: Application development using Microsoft SQL Server 2000

Engine Enhancements Engine Enhancements Indexes on ViewsIndexes on Views Defining an Index on a ViewDefining an Index on a View

A.k.a., Materialized viewsA.k.a., Materialized views The view may be a join, an aggregation, or The view may be a join, an aggregation, or

their combinationtheir combination Once the index is created, the contents of Once the index is created, the contents of

the view are persisted the view are persisted The index is maintained automatically, as The index is maintained automatically, as

with any other indexwith any other index The optimizer may use the index on a view The optimizer may use the index on a view

even if the view is not directly referenced in even if the view is not directly referenced in the querythe query

Page 14: Application development using Microsoft SQL Server 2000

Engine Enhancements Engine Enhancements Indexes on ViewsIndexes on Views Creating an Index on a View – Creating an Index on a View –

ConsiderationsConsiderations SET options consideration SET options consideration

and DETERMINISM and DETERMINISM CREATE VIEW with SCHEMABINDINGCREATE VIEW with SCHEMABINDING CREATE INDEXCREATE INDEX

Page 15: Application development using Microsoft SQL Server 2000

XML SupportXML SupportXML Query ResultsXML Query Results SQL Language ExtensionSQL Language Extension

SELECT…SELECT…

FROM…FROM…

WHERE…WHERE…

ORDER BY…ORDER BY…

FOR XML (raw | FOR XML (raw |

auto [, ELEMENTS] |auto [, ELEMENTS] |

explicit)explicit)

[, XMLData][, XMLData]

[, BINARY base64])[, BINARY base64])

Page 16: Application development using Microsoft SQL Server 2000

XML SupportXML SupportFOR XML – Raw ModeFOR XML – Raw Mode One <Row> Element Per Row in the One <Row> Element Per Row in the

Result SetResult Set No Nested ElementsNo Nested Elements Columns / Values in the Result Set Columns / Values in the Result Set

Are Attributes / Values on the Are Attributes / Values on the <Row><Row>

Similar to CSV but in XML FormatSimilar to CSV but in XML Format

Page 17: Application development using Microsoft SQL Server 2000

XML SupportXML SupportFOR XML – Auto ModeFOR XML – Auto Mode Table / View Name in the Database Table / View Name in the Database

Used for the Element NameUsed for the Element Name Column Names Used for AttributesColumn Names Used for Attributes Supports Nested XML OutputSupports Nested XML Output

Nesting determined by ordering of columns Nesting determined by ordering of columns in SELECT clausein SELECT clause

Sibling relationships not supportedSibling relationships not supported

Change Names Using Table and Change Names Using Table and Column AliasesColumn Aliases

Page 18: Application development using Microsoft SQL Server 2000

XML SupportXML SupportFOR XML – Explicit ModeFOR XML – Explicit Mode Provides Complete Control Over Format Provides Complete Control Over Format

of XML Resultof XML Result Columns Can Be Individually Mapped to Columns Can Be Individually Mapped to

Attributes or Sub-ElementsAttributes or Sub-Elements Supports arbitrary nestingSupports arbitrary nesting Sibling relationships supportedSibling relationships supported

Collapses / Hoists HierarchyCollapses / Hoists Hierarchy Constructs ID/IDREF RelationshipsConstructs ID/IDREF Relationships CDATA Sections in XML OutputCDATA Sections in XML Output Stores XML AnnotationsStores XML Annotations

Page 19: Application development using Microsoft SQL Server 2000

XML Support XML Support HTTP Access – URL TypesHTTP Access – URL Types

URL QueryURL Query http://server/vroot?sql=“…”http://server/vroot?sql=“…”

Direct QueryDirect Query http://server/vroot/dbobject/http://server/vroot/dbobject/xpathxpath

TemplateTemplate http://server/vroot/vname?http://server/vroot/vname?paramsparams

XML ViewXML View http://server/vroot/vname/http://server/vroot/vname/xpathxpath??paramsparams

Page 20: Application development using Microsoft SQL Server 2000

XML Support XML Support OpenXMLOpenXML Used with T-SQL Stored ProceduresUsed with T-SQL Stored Procedures Provides a Relational View on XMLProvides a Relational View on XML Specifies Row and Column Selectors Specifies Row and Column Selectors

Using an XPathUsing an XPath SupportsSupports

Attribute and element-centric mappings Attribute and element-centric mappings XML annotation / overflow columnXML annotation / overflow column Hierarchy supportHierarchy support

Page 21: Application development using Microsoft SQL Server 2000

Multiple InstancesMultiple Instances

DefaultDefault Only one activeOnly one active Version switchVersion switch

NamedNamed All instances All instances

can be activecan be active

SQL Server 2000SQL Server 2000

{{

SQL Server 2000SQL Server 2000

SQL Server 2000SQL Server 2000

SQL Server 2000SQL Server 2000

SQL Server 7.0 or 2000SQL Server 7.0 or 2000

SQL Server 6.5 SQL Server 6.5

Up to Up to 1515

Page 22: Application development using Microsoft SQL Server 2000

Multiple InstancesMultiple Instances

Support multiple SQL server instances Support multiple SQL server instances on single machineon single machine

Applications:Applications: Application hosting Application hosting Secured Application IsolationSecured Application Isolation Development and testingDevelopment and testing Take Full advantage of powerful hardwareTake Full advantage of powerful hardware

Page 23: Application development using Microsoft SQL Server 2000

More ResourcesMore Resources

msdn.microsoft.commsdn.microsoft.com

www.microsoft.com/sqlwww.microsoft.com/sql

msdn.microsoft.com/sqlservermsdn.microsoft.com/sqlserver

www.microsoft.com/technet/sqlwww.microsoft.com/technet/sql

msdn.microsoft.com/xmlmsdn.microsoft.com/xml

Page 24: Application development using Microsoft SQL Server 2000