Data Types Inn SQL Server
Data Types Inn SQL Server
INTEGER 0-9
*BIGINT
Stores lenth of upto 18 digits..
*INT
Stores upto 5 digits
*SMALLINT
Stores upto 4 digits
*TINYINT
Stores upto 2 digits
Character:
CHAR Data Type is a Fixed Length Data Type. For example if you declare a variable/column of CHAR (10) data type, then it will always take 10 bytes irrespective of
whether you are storing 1 character or 10 character in this variable or column. And in this example as we have declared this variable/column as CHAR(10), so we can
store max 10 characters in this column.
On the other hand VARCHAR is a variable length Data Type. For example if you declare a variable/column of VARCHAR (10) data type, it will take the no. of bytes
equal to the number of characters stored in this column. So, in this variable/column if you are storing only one character then it will take only one byte and if we are
storing 10 characters then it will take 10 bytes. And in this example as we have declared this variable/column as VARCHAR (10), so we can store max 10 characters in
this column
UNICODE : NCHAR
A Unicode character takes more bytes to store the data in the database. As we all know, many global industries wants to increase their business worldwide and grow at the same time, they would want
to widen their business by providing services to the customers worldwide by supporting different languages like Chinese, Japanese, Korean and Arabic. Many websites these days are supporting
international languages to do their business and to attract more and more customers and that makes life easier for both the parties.In SQL Server 2008 we get a new DATE date type that
allows you to store a date without a time
NON-UNICODE : NVARCHAR
Non Unicode is exactly opposite to Unicode. Using non Unicode it is easy to store languages like ‘English’ but not other Asian languages that need more bits to store correctly otherwise truncation
will occur.
Ex : char (10)
Varchar(10)
TEXT
It was equal to varchar(max) this data type will be removed in a future version of Microsoft SQL Server. Avoid using these data types in new development work use
varchar(max) instead.
NUMERIC OR DECIMAL
Approximate numeric data types do not store the exact values specified for many numbers; they store an extremely close approximation of the value.
Hewre syntax decimal(p,s)
Ex:decimal(10,2)
Here total elements are stored in this variable is 10 and and total elements 2 digits elements stored after point..
);
Time: is hh-mm-ss
We have predefine getdate() function which gets the current date and time
BIT ....
Datetype takes values as true and false i.e 1 is taken as true and 0 is takes as false
insert into tt values('true')
insert into tt values(1)
select * from tt
Anserwe is always 1
IMAGE
It was equal to varbinary(max) this data type will be removed in a future version of Microsoft SQL Server. Avoid using these data types in new development work use
varbinary(max) instead.
BINARY VALUES:
To hold the binary values likes images, audio clips and video clips we use the following types.
binary [ ( n ) ]
Fixed-length binary data with a length of n bytes, where n is a value from 1 through 8,000. The storage size is n bytes.
varbinary [ ( n | max) ]
Variable-length binary data. n can be a value from 1 through 8,000. max indicates that the maximum storage size is 2^31-1 bytes. The storage size is the actual length of the data
entered + 2 bytes.
select * from ty
o/p is 0x00000000000000000000002B
MONEY:
Its used to store currency values...