DATA TYPES
VERSION 1.0

By Naji El Kotob
Data Type?


Indicates the type of data the field will contain.
Data Types





Numeric data types
Character data types
Temporal (date and/or time) data types
Miscellaneous data type...
Precision, Scale, and Length


Precision is the number of digits in a number. Scale
is the number of digits to the right ...
Custom Data Type (Alias)
CREATE TYPE dbo.ProjectCode
FROM char(6)
NOT NULL
Special Column Types


Computed columns




Identity columns




An Identity column is often used for primary key val...
Converts an expression of one data
type to another.
Source: MSDN
CAST and CONVERT


Explicitly converts an expression of one data type
to another.
CAST and CONVERT: Syntax


CAST ( expression AS data_type )



CONVERT ( data_type [ ( length ) ] , expression [ , style...
CAST and CONVERT: DEMO




PRINT 'Date/time in format MON DD YYYY HH:MI
AM (OR PM): ' + CONVERT(CHAR(19),GETDATE())
PRINT '6) Date/time in form...
DECLARE @d DATETIME
SET @d = '2008-02-09 10:31 PM' -- Length 19
SELECT REPLACE(CONVERT(CHAR(16),@d,120),'-','/')
DECLARE @d DATETIME
 SET @d = '2008-02-09 10:31 PM'
 SELECT DATENAME(DAY,@d)

DECLARE @id char(4)
SET @id = '123'
SET @id = CAST(@id AS int) + 1
SELECT @id
SELECT CAST(10.6496 AS int)
SELECT CAST(15.279769 AS money)
References




Data Types http://technet.microsoft.com/enus/library/ms187752.aspx
Cast and Convert http://msdn.microsoft...
Upcoming SlideShare
Loading in...5
×

T-SQL Data Types (Quick Overview)

338

Published on

T-SQL Data Types (Quick Overview) - Version 1.0

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
338
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
15
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

T-SQL Data Types (Quick Overview)

  1. 1. DATA TYPES VERSION 1.0 By Naji El Kotob
  2. 2. Data Type?  Indicates the type of data the field will contain.
  3. 3. Data Types     Numeric data types Character data types Temporal (date and/or time) data types Miscellaneous data types
  4. 4. Precision, Scale, and Length  Precision is the number of digits in a number. Scale is the number of digits to the right of the decimal point in a number.  For example, the number 123.45 has a precision of 5 and a scale of 2.
  5. 5. Custom Data Type (Alias) CREATE TYPE dbo.ProjectCode FROM char(6) NOT NULL
  6. 6. Special Column Types  Computed columns   Identity columns   An Identity column is often used for primary key values UniqueIdentifier columns   Virtual columns that are not physically stored in the table Guaranteed to be universally unique TimeStamp columns  Guaranteed to be unique within a database
  7. 7. Converts an expression of one data type to another.
  8. 8. Source: MSDN
  9. 9. CAST and CONVERT  Explicitly converts an expression of one data type to another.
  10. 10. CAST and CONVERT: Syntax  CAST ( expression AS data_type )  CONVERT ( data_type [ ( length ) ] , expression [ , style ] )
  11. 11. CAST and CONVERT: DEMO
  12. 12.   PRINT 'Date/time in format MON DD YYYY HH:MI AM (OR PM): ' + CONVERT(CHAR(19),GETDATE()) PRINT '6) Date/time in format DD MON YYYY HH:MM:SS:MMM(24H): ' + CONVERT(CHAR(24),GETDATE(),113)
  13. 13. DECLARE @d DATETIME SET @d = '2008-02-09 10:31 PM' -- Length 19 SELECT REPLACE(CONVERT(CHAR(16),@d,120),'-','/')
  14. 14. DECLARE @d DATETIME  SET @d = '2008-02-09 10:31 PM'  SELECT DATENAME(DAY,@d) 
  15. 15. DECLARE @id char(4) SET @id = '123' SET @id = CAST(@id AS int) + 1 SELECT @id
  16. 16. SELECT CAST(10.6496 AS int)
  17. 17. SELECT CAST(15.279769 AS money)
  18. 18. References   Data Types http://technet.microsoft.com/enus/library/ms187752.aspx Cast and Convert http://msdn.microsoft.com/enus/library/ms187928.aspx
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×