Sqlserver 2008 r2

957 views

Published on

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

  • Be the first to like this

No Downloads
Views
Total views
957
On SlideShare
0
From Embeds
0
Number of Embeds
218
Actions
Shares
0
Downloads
12
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Sqlserver 2008 r2

  1. 1. Sqlserver 2008 R2<br />Kashif Akram<br />
  2. 2. New Datatypes Agenda <br />Datatypes<br />CRL <br />Reporting Services <br />
  3. 3. Datetime<br />DATE: As you can imagine, the DATE data type only stores a date in the format of YYYY-MM-DD. It has a range of 0001-01-01 through 9999-12-32, which should be adequate for most business and scientific applications. The accuracy is 1 day, and it only takes 3 bytes to store the date.<br />TIME: TIME is stored in the format: hh:mm:ss.nnnnnnn, with a range of 00:00:00.0000000 through 23:59:59:9999999 and is accurate to 100 nanoseconds. Storage depends on the precision and scale selected, and runs from 3 to 5 bytes.<br />
  4. 4. DECLARE @d DATE <br />SET @d = GETDATE() <br />SELECT @d -- outputs '2008-04-06 ' <br />SET @d = '1234-03-22 11:25:09' <br />SELECT @d -- outputs '1234-03-22 ' <br />
  5. 5. CREATE TABLE #times( <br /> T TIME, <br /> T1 TIME(1), <br /> T5 TIME(5), <br /> T7 TIME(7) <br /> ) <br />INSERT INTO #times VALUES ( <br /> '01:02:03.1234567', <br /> '01:02:03.1234567', <br /> '01:02:03.1234567', <br /> '01:02:03.1234567') <br />SELECT * FROM #times <br />T T1 T5 T7 <br />---------------- ---------------- ---------------- ---------------- <br />01:02:03.1234567 01:02:03.1000000 01:02:03.1234600 01:02:03.1234567 <br />
  6. 6. DATETIME2: DATETIME2 is very similar to the older DATETIME data type, but has a greater range and precision. The format is YYYY-MM-DD hh:mm:ss:nnnnnnnm with a range of 0001-01-01 00:00:00.0000000 through 9999-12-31 23:59:59.9999999, and an accuracy of 100 nanoseconds. Storage depends on the precision and scale selected, and runs from 6 to 8 bytes.<br />DATETIMEOFFSET: DATETIMEOFFSET is similar to DATETIME2, but includes additional information to track the time zone. The format is YYYY-MM-DD hh:mm:ss[.nnnnnnn] [+|-]hh:mm with a range of 0001-01-01 00:00:00.0000000 through 0001-01-01 00:00:00.0000000 through 9999-12-31 23:59:59.9999999 (in UTC), and an accuracy of 100 nanoseconds. Storage depends on the precision and scale selected, and runs from 8 to 10 bytes.<br />
  7. 7. DECLARE @dateA DATETIME2 = '2008-04-05 01:02:03.12345' <br />PRINT @dateA -- outputs 2008-04-05 01:02:03.1234500 <br />DECLARE @dateB DATETIME2(4) = '2008-04-05 01:02:03.12345' <br />PRINT @dateB -- outputs 2008-04-05 01:02:03.1235 <br />
  8. 8. DECLARE @today DATETIMEOFFSET = '2008-04-05T01:02:03.1234567-05:00' <br />PRINT @today -- outputs 2008-04-05 01:02:03.1234567 -05:00 <br />DECLARE @today2 DATETIMEOFFSET(2) = '2008-04-05T01:02:03.1234567-05:00' <br />PRINT @today2 -- outputs 2008-04-05 01:02:03.12 -05:00 <br />
  9. 9. Spatial<br />GEOMETRY: The GEOMETRY data type is used to store planar (flat-earth) data. It is generally used to store XY coordinates that represent points, lines, and polygons in a two-dimensional space. For example storing XY coordinates in the GEOMETRY data type can be used to map the exterior of a building.<br />GEOGRAPHY: The GEOGRAPHY data type is used to store ellipsoidal (round-earth) data. It is used to store latitude and longitude coordinates that represent points, lines, and polygons on the earth’s surface. For example, GPS data that represents the lay of the land is one example of data that can be stored in theGEOGRAPHY data type.<br />
  10. 10. DECLARE @shape geometry <br />SET @shape = geometry::STPolyFromText('POLYGON (( <br /> 47.653 -122.358, <br /> 47.653 -122.354, <br /> 47.657 -122.354, <br /> 47.653 -122.350, <br /> 47.645 -122.350, <br /> ... (snip) <br /> 47.651 -122.355, <br /> 47.653 -122.358))', 0) <br />
  11. 11. SELECT @shape.STEnvelope().ToString() <br />-- outputs something like <br />/* <br /> POLYGON (( <br /> 47.657 -122.358, <br /> 47.657 -122.350, <br /> 47.645 -122.350, <br /> 47.645 -122.358, <br /> 47.657 -122.358)) <br />*/ <br />
  12. 12. HIERARCHYID<br />Organizational structures<br />A set of tasks that make up a larger projects (like a GANTT chart)<br />File systems (folders and their sub-folders)<br />A classification of language terms<br />A bill of materials to assemble or build a product<br />A graphical representation of links between web pages<br />
  13. 13. CREATE TABLE #Categories ( <br />CategoryID INT IDENTITY(1,1), <br />CategoryNode HIERARCHYID NOT NULL, <br />CategName NVARCHAR(40) NOT NULL <br /> ) <br />
  14. 14. DECLARE @root HIERARCHYID = hierarchyid::GetRoot() <br />INSERT INTO #Categories (CategoryNode, CategName) <br /> VALUES (@root, 'All #Categories') <br />-- insert the 'Electronics' category <br />DECLARE @electronics HIERARCHYID <br />SELECT @electronics = @root.GetDescendant(NULL, NULL) <br />INSERT INTO #Categories (CategoryNode, CategName) <br /> VALUES (@electronics, 'Electronics') <br />-- insert the 'Music' category after 'Electronics' <br />DECLARE @music HIERARCHYID <br />SELECT @music = @root.GetDescendant(NULL, @electronics) <br />INSERT INTO #Categories (CategoryNode, CategName) <br /> VALUES (@music, 'Music') <br />
  15. 15. -- insert the 'Apparel' category between 'Electronics' and 'Music' <br />SELECT @music = @root.GetDescendant(@music, @electronics) <br />INSERT INTO #Categories (CategoryNode, CategName) <br /> VALUES (@music, 'Apparel') <br />-- insert some children under 'Electronics' <br />DECLARE @video HIERARCHYID <br />-- We could do a simple @category.GetDescendant() but, let's <br />-- show something that is more likely to happen <br />SELECT @video = CategoryNode.GetDescendant(NULL, NULL) <br /> FROM #Categories WHERE CategName ='Electronics' <br />INSERT INTO #Categories (CategoryNode, CategName) <br /> VALUES (@video, 'Video Equipment') <br />-- insert some children under 'Video Equipment' <br />DECLARE @tvs HIERARCHYID <br />SELECT @tvs = @video.GetDescendant(NULL, NULL) <br />INSERT INTO #Categories (CategoryNode, CategName) <br /> VALUES (@tvs, 'Televisions') <br />DECLARE @players HIERARCHYID <br />SELECT @players = @video.GetDescendant(NULL, @tvs) <br />INSERT INTO #Categories (CategoryNode, CategName) <br /> VALUES (@players, 'DVD - BluRay')<br />
  16. 16. SELECT <br />CategoryID, CategName, <br />CategoryNode, <br />CategoryNode.ToString() AS Path <br />FROM #Categories <br />
  17. 17. FILESTREAM<br />Transact-SQL can be used to SELECT, INSERT, UPDATE, DELETE FILESTREAM data.<br />By default, FILESTREAM data is backed up and restored as part of the database file. If you want, there is an option available so you can backup a database without the FILESTREAM data.<br />The size of the stored data is only limited by the available space of the file system. Standard VARBINARY(MAX) data is limited to 2 GB.<br />
  18. 18.
  19. 19. USE Production;<br />GO<br />CREATE TABLE DocumentStore (<br />DocumentID INT IDENTITY PRIMARY KEY,<br /> Document VARBINARY (MAX) FILESTREAM NULL,<br />DocGUID UNIQUEIDENTIFIER NOT NULL ROWGUIDCOL<br /> UNIQUE DEFAULT NEWID ())<br />FILESTREAM_ON FileStreamGroup1;<br />GO<br />
  20. 20. CLR<br />EXEC sp_configure 'clr enabled', '1'<br />reconfigure<br />

×