SQL Server 2008 for .NET Developers

1,722 views
1,637 views

Published on

New features of interest to .NET developers - Spatial Data Types, Filestream, CLR, more...

Published in: Education, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,722
On SlideShare
0
From Embeds
0
Number of Embeds
7
Actions
Shares
0
Downloads
70
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • SQL Server 2008 for .NET Developers

    1. 1. SQL Server 2008 for .NET Developers <ul><li>Lynn Langit – Developer Evangelist – Microsoft </li></ul><ul><li>http://blogs.msdn.com/SoCalDevGal </li></ul>
    2. 2. What Will We cover? <ul><li>SQL Server Spatial support </li></ul><ul><li>BLOB storage (Filestream) </li></ul><ul><li>T-SQL Enhancements </li></ul><ul><ul><li>Table-valued parameters </li></ul></ul><ul><ul><li>New date / time </li></ul></ul><ul><ul><li>More </li></ul></ul><ul><li>Visual Studio integration </li></ul><ul><ul><li>SQL CLR </li></ul></ul><ul><ul><li>Business Intelligence </li></ul></ul><ul><ul><ul><li>Reporting Services </li></ul></ul></ul><ul><ul><ul><li>More </li></ul></ul></ul>
    3. 3. What is Spatial Data? <ul><li>Location-based questions </li></ul><ul><ul><li>Which roads intersect property or each other? </li></ul></ul><ul><ul><li>How many stores/restaurants/houses/car dealerships are located within a geographical area? </li></ul></ul><ul><li>Spatial Data Types </li></ul><ul><ul><li>Geometry </li></ul></ul><ul><ul><ul><li>Flat Earth model & X, Y coordinates </li></ul></ul></ul><ul><ul><li>Geography </li></ul></ul><ul><ul><ul><li>Round Earth model uses Latitude and Longitude coordinates </li></ul></ul></ul><ul><ul><ul><li>Can span only one logical hemisphere (more will throw exception) </li></ul></ul></ul><ul><li>Query for location info as any SQL Server data type </li></ul><ul><ul><li>Data types dictated by OpenGIS standard </li></ul></ul><ul><ul><li>New spatial index type </li></ul></ul>
    4. 4. Representing Spatial Data <ul><li>Geospatial data in SQL Server </li></ul><ul><ul><li>Stored in proprietary binary format </li></ul></ul><ul><ul><li>Can be input using simple text </li></ul></ul><ul><ul><ul><li>Parse methods convert text into internal storage format </li></ul></ul></ul><ul><ul><li>Represents areas using </li></ul></ul><ul><ul><ul><li>Points, Linestrings, Polygons </li></ul></ul></ul><ul><ul><ul><li>MultiPoints, MultiLinestrings, MultiPolygons </li></ul></ul></ul><ul><ul><ul><li>GeomCollections </li></ul></ul></ul><ul><li>Define Polygons in counter-clockwise direction </li></ul><ul><ul><li>Interior areas (“holes”) must be defined in clockwise direction </li></ul></ul><ul><li>Supports various calculations and methods </li></ul><ul><ul><li>Spatial Reference ID (SRID) identifies ellipsoid (flat/round, meters/feet) </li></ul></ul><ul><ul><li>Only instances with like SRID can be directly compared </li></ul></ul>
    5. 5. SQL Server Geospatial and Virtual Earth
    6. 6. About BLOBs <ul><li>1. Old way #1 </li></ul><ul><ul><li>Store BLOBs in DB as varbinary (max) up to 2 GB each </li></ul></ul><ul><ul><li>Easier management, but can be poor performance </li></ul></ul><ul><li>2. Old way # 2 </li></ul><ul><ul><li>Store BLOBS in File system, path (link) in db </li></ul></ul><ul><ul><li>Good performance, but complex management </li></ul></ul><ul><li>3. New way </li></ul><ul><ul><li>Best of both via Filestream attribute </li></ul></ul><ul><ul><li>Applied to varbinary(max) data type </li></ul></ul><ul><ul><li>Integrated database security </li></ul></ul><ul><ul><li>Uses dedicated Filegroup (easier maintenance) </li></ul></ul><ul><ul><li>Limits *no snapshots or mirroring and more </li></ul></ul>
    7. 7. Using Filestream <ul><li>1. Enable Filestream for the machine </li></ul><ul><ul><li>For T-SQL access </li></ul></ul><ul><ul><li>For file I/O streaming access </li></ul></ul><ul><ul><li>Name of share for storage </li></ul></ul><ul><ul><li>For streaming remote clients </li></ul></ul><ul><ul><li>Required integrated security </li></ul></ul><ul><li>2. Enable Filestream for the server instance </li></ul><ul><ul><li>sp_configure filestream_access_level, (0, 1, 2) </li></ul></ul><ul><ul><li>Can limit to T-SQL access only (option 1) </li></ul></ul><ul><li>3. Create Filestream-enabled database </li></ul><ul><ul><li>FILEGROUP FgName CONTAINS FILESTREAM (NAME = …) </li></ul></ul><ul><ul><li>Name is the directory (storage) name </li></ul></ul><ul><ul><li>Name (i.e. folder) must NOT exist prior to creating DB </li></ul></ul><ul><li>Create table with Filestream column(s) </li></ul><ul><ul><li>With specific requirements, next slide>> </li></ul></ul>
    8. 8. Filestream Columns <ul><li>Tables with Filestream columns must… </li></ul><ul><ul><li>Contain a Uniqueidentifier column that is </li></ul></ul><ul><ul><ul><li>Not nullable </li></ul></ul></ul><ul><ul><ul><li>Uses the ROWGUIDCOL attribute </li></ul></ul></ul><ul><ul><ul><li>Max one per table </li></ul></ul></ul><ul><ul><ul><li>Has a unique constraint on it </li></ul></ul></ul><ul><li>Can have more than ‘Filestream’ column </li></ul><ul><ul><li>Varbinary(max) with Filestream attribute </li></ul></ul><ul><ul><li>Will probably have a default value assigned </li></ul></ul><ul><li>Can be manipulated using </li></ul><ul><ul><li>T-SQL </li></ul></ul><ul><ul><li>OpenSqlFilestream function - sample </li></ul></ul><ul><ul><li>Performance comparison here </li></ul></ul>
    9. 9. Using Filestream
    10. 10. Enhancements to T-SQL <ul><li>Table Value Parameters </li></ul><ul><li>New Date/Time types </li></ul><ul><li>Time zone awareness </li></ul><ul><li>New MERGE keyword </li></ul><ul><li>New shorthand notation </li></ul>
    11. 11. Table Value Parameters <ul><li>CREATE TYPE as TABLE </li></ul><ul><ul><li>Multiple tables inserted/updated within single transaction (MARS-like capability for writing) </li></ul></ul><ul><ul><li>Can pass strongly-typed arrays to stored proc as single call </li></ul></ul><ul><li>ADO.NET updated to include support </li></ul><ul><ul><li>Param type: SqlDbType.Structured </li></ul></ul><ul><ul><li>Can use PK, Unique, Check constraints </li></ul></ul><ul><ul><li>Index only for PK or Unique, no stats </li></ul></ul><ul><ul><li>Can specify the sort order </li></ul></ul><ul><ul><li>Can NOT use Defaults </li></ul></ul>
    12. 12. When to use TVPs <ul><li>TVPs </li></ul><ul><ul><li>Pass large number of rows – uses tempdb </li></ul></ul><ul><ul><li>Results in simpler CRUD stored procs </li></ul></ul><ul><ul><li>READONLY after initial population </li></ul></ul><ul><li>Temp table or CTE </li></ul><ul><ul><li>CTEs – no indexing, in memory (unless out of memory, then in tempdb) </li></ul></ul><ul><ul><li>Can not pass as param </li></ul></ul>
    13. 13. T-SQL Enhancements Table Valued Parameters
    14. 14. Dates and Time <ul><li>Several new types added </li></ul><ul><ul><li>datetime2 </li></ul></ul><ul><ul><li>date </li></ul></ul><ul><ul><li>time </li></ul></ul><ul><ul><li>datetimeoffset </li></ul></ul><ul><li>New functions added </li></ul><ul><ul><li>CONVERT </li></ul></ul><ul><ul><li>SYS* Functions </li></ul></ul><ul><ul><li>DATEDIFF </li></ul></ul>
    15. 15. MERGE <ul><li>Insert, Update, Delete with one keyword </li></ul><ul><ul><li>Merge two tables, source and target </li></ul></ul><ul><ul><ul><li>WHEN MATCHED </li></ul></ul></ul><ul><ul><ul><li>WHEN TARGET NOT MATCHED </li></ul></ul></ul><ul><ul><ul><li>WHEN SOURCE NOT MATCHED </li></ul></ul></ul><ul><ul><li>Syntax and use can be complex </li></ul></ul><ul><ul><li>MERGE syntax from SQL Server BOL </li></ul></ul>
    16. 16. Shorthand Notation <ul><li>Like .NET languages (C# or Visual Basic .NET) </li></ul><ul><li>Declare variable & assign value in one line of code </li></ul><ul><li>Compound assignment, i.e ‘+=‘, etc.. </li></ul>
    17. 17. T-SQL Enhancements Date/Time, Merge, Shorthand
    18. 18. Visual Studio Integration <ul><li>Enhanced project types </li></ul><ul><ul><li>Analysis Services </li></ul></ul><ul><ul><li>Integration Services </li></ul></ul><ul><ul><li>Reporting Services </li></ul></ul><ul><li>Entity Framework </li></ul><ul><li>CLR Integration </li></ul>
    19. 19. Entity Framework <ul><li>Models relational data using entities (OR/M tool) </li></ul><ul><ul><li>Can model any relational data source for data access (provider may be required) </li></ul></ul><ul><ul><li>Application-specific domain </li></ul></ul><ul><ul><li>You can work at a higher level of abstraction </li></ul></ul><ul><ul><li>Appropriate amount of information returned </li></ul></ul><ul><ul><li>Lazy-loaded </li></ul></ul><ul><li>What is an entity? </li></ul><ul><ul><li>Structurally like an object (noun) </li></ul></ul><ul><ul><ul><li>Has scalars and relationships </li></ul></ul></ul><ul><ul><ul><li>Has identity </li></ul></ul></ul><ul><ul><ul><li>Not tied specifically to SQL Server </li></ul></ul></ul>
    20. 20. Visual Studio Integration Entity Framework
    21. 21. SQL CLR <ul><li>SQL CLR is “off by default” for security reasons </li></ul><ul><ul><li>Must activate (instance) then per database to enable </li></ul></ul><ul><ul><li>Code executes in SQL Server processing stream </li></ul></ul><ul><li>SQL Server has the ability to execute managed code </li></ul><ul><ul><li>Stored procedures & Triggers </li></ul></ul><ul><ul><li>User-defined Types & Aggregates – extended size (up to 2 GB) </li></ul></ul><ul><ul><li>Regular Functions & Table value functions </li></ul></ul><ul><li>Use mostly for complex processing </li></ul><ul><ul><li>Use for Functions or Aggregates </li></ul></ul><ul><ul><li>Do not use for CRUD operations </li></ul></ul>
    22. 22. Programming SQL CLR <ul><li>Use Visual Studio templates for SQL CLR constructs </li></ul><ul><ul><li>Uses Database project type </li></ul></ul><ul><ul><li>Can be remotely debugged </li></ul></ul><ul><ul><li>Metadata (attributes) control SQL Server behavior </li></ul></ul><ul><ul><ul><li>Microsoft.SqlServer.Server.xxx </li></ul></ul></ul><ul><ul><ul><li>SqlProcedure, SqlFunction, SqlUserDefinedAggregate, SqlTrigger, SqlUserDefinedType, SqlFacet, SqlMethod </li></ul></ul></ul><ul><li>Microsoft.SqlServer.Server namespace (retrieves/returns data) </li></ul><ul><ul><li>Very ADO.NET-like, but not ADO.NET </li></ul></ul><ul><ul><li>Uses SqlContext.Pipe </li></ul></ul><ul><ul><li>Assign CAS permission set (Safe, External, Unsafe) </li></ul></ul><ul><ul><li>Use for complex processing, i.e. RegEx parsing, etc… </li></ul></ul>
    23. 23. Visual Studio Integration SQL CLR
    24. 24. Business Intelligence <ul><li>SSAS – Analysis Services </li></ul><ul><ul><li>Date storage and query </li></ul></ul><ul><ul><li>OLAP cubes or Data Mining Structures </li></ul></ul><ul><ul><li>BIDS to create </li></ul></ul><ul><ul><li>SSMS to administer </li></ul></ul><ul><li>SSIS – Integration Services </li></ul><ul><ul><li>ETL tool </li></ul></ul><ul><li>SSRS - Reporting Services </li></ul><ul><ul><li>Enterprise Reporting </li></ul></ul><ul><li>BI can use any data source </li></ul><ul><li>Data Warehousing </li></ul><ul><li>Data Mining </li></ul>
    25. 25. Reporting Services <ul><li>SQL Server standard for reporting </li></ul><ul><ul><li>Managed enterprise reporting </li></ul></ul><ul><ul><li>Ad-hoc reporting </li></ul></ul><ul><ul><li>Embedded reporting </li></ul></ul><ul><ul><li>Web-based reporting </li></ul></ul><ul><ul><li>Included in SQL Server 2008 Express w/Advanced Services </li></ul></ul><ul><li>Reports can be formatted in a variety of ways </li></ul><ul><ul><li>PDF, Word 2007, HTML </li></ul></ul><ul><li>Reports are exposed via a Web Service </li></ul><ul><ul><li>Can be integrated with SharePoint </li></ul></ul><ul><ul><li>Dependency on IIS removed (uses http.sys) </li></ul></ul>
    26. 26. Programming Reports <ul><li>Design reports in Visual Studio 2008 SP1 </li></ul><ul><ul><li>Query for data </li></ul></ul><ul><ul><li>Assign query results to report </li></ul></ul><ul><ul><li>Design report style </li></ul></ul><ul><ul><ul><li>Colors, Fonts, etc… </li></ul></ul></ul><ul><ul><li>Deploy report </li></ul></ul><ul><ul><ul><li>Web Service </li></ul></ul></ul><ul><ul><ul><li>SharePoint Services </li></ul></ul></ul><ul><li>Wizard available for initial report design – also Report Builder </li></ul><ul><li>Enhanced configuration and administration tool </li></ul>
    27. 27. Visual Studio Integration Reporting Services and more
    28. 28. But there’s more… <ul><li>For Developers </li></ul><ul><ul><li>Change Data Capture </li></ul></ul><ul><ul><li>Filtered Indexes </li></ul></ul><ul><ul><li>Hierarchy ID ( ) </li></ul></ul><ul><ul><li>Sparse data columns </li></ul></ul><ul><ul><li>XML Enhancements </li></ul></ul><ul><ul><li>Integrated Full-Text Search </li></ul></ul><ul><li>For Administrators </li></ul><ul><ul><li>Policy-based management </li></ul></ul><ul><ul><li>Auditing enhancements </li></ul></ul><ul><ul><li>Transparent Encryption </li></ul></ul><ul><ul><li>Compression </li></ul></ul><ul><ul><li>PowerShell integration </li></ul></ul><ul><ul><li>More… </li></ul></ul>
    29. 29. Microsoft Press Publications Lynn’s blog http://blogs.msdn.com/SoCalDevGal
    30. 30. Get Microsoft Software for FREE <ul><li>For high school and college students - DreamSpark </li></ul><ul><li>For startup businesses - BizSpark </li></ul><ul><li>For everyone - Express editions – VS and SQL - here </li></ul>

    ×