90 likes | 378 Views
Data Types. Integer Int Smallint Tinyint Bit Packed Decimal Decimal(p,s) Floating Point Float Real Character Char(n) Varchar(n). Unicode Nchar(n) Nvarchar(n) Ntext Monetary Money Smallmoney Date and time Datetime Smalldatetime. Built In Data Types. Exotic Data Types.
E N D
Integer Int Smallint Tinyint Bit Packed Decimal Decimal(p,s) Floating Point Float Real Character Char(n) Varchar(n) Unicode Nchar(n) Nvarchar(n) Ntext Monetary Money Smallmoney Date and time Datetime Smalldatetime Built In Data Types
Exotic Data Types • Binary • Binary(n) • Varbinary(n) • Long text/BLOB • Text • Image • Numerics • Cursor • Timestamp • uniqueidentifier
User-defined Data Type (UDT) • A user-defined data type provides a convenient way to guarantee consistent use of the underlying native data types for columns known to have the same domain of possible values. • For example, you want all phone numbers stored in the database the same way.
UDT example Exec sp_addtype phone_number, ‘char(10)’, ‘not null’ Go to query analyzer and and define this datatype
Sp_addtype • A system stored procedure that creates catalog entries for UDT’s • Syntax sp_addtype [ @typename = ] type, [ @phystype = ]system_data_type [ , [ @nulltype = ] 'null_type' ] [ , [ @owner = ] 'owner_name' ]
Using UDTs in a table • Create the following UDTs • Ssn char(11) not null • Birthdate datetime null • Use those datatypes to create this table • Empl • Name varchar(20) not null • SocNbr ssn • Bdate birthdate
Testing UDTs • Write and insert statement to put data into the new table
Limitations of UDTs • No defaults • No check constraint • No subtyping or inheritance