0% found this document useful (0 votes)
41 views

Data Types Inn SQL Server

SQL Server supports several data types for integers, characters, text, dates, times, binary values, and currency values. Integer data types store whole numbers and include tinyint, smallint, int, and bigint. Character data types store text values and include char and varchar, with the latter being variable length. Date and time types include date, time, datetime, and datetime2 for storing dates, times, and combined date-time values. Image and varbinary types can store binary values like images. Money is used specifically for currency values.

Uploaded by

latha sri
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views

Data Types Inn SQL Server

SQL Server supports several data types for integers, characters, text, dates, times, binary values, and currency values. Integer data types store whole numbers and include tinyint, smallint, int, and bigint. Character data types store text values and include char and varchar, with the latter being variable length. Date and time types include date, time, datetime, and datetime2 for storing dates, times, and combined date-time values. Image and varbinary types can store binary values like images. Money is used specifically for currency values.

Uploaded by

latha sri
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

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

NCHAR AnD NVARCHAR

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)

P means total number of elements stored in numeric datatype ..


S means number of elements stored after . (point) decleration..

Ex:decimal(10,2)
Here total elements are stored in this variable is 10 and and total elements 2 digits elements stored after point..

CREATE TABLE dbo.MyTable1


(
MyDecimalColumn decimal(5,2)
,MyNumericColumn numeric(10,5)

);

INSERT INTO dbo.MyTable1 VALUES (123, 12345.12);

select * from MyTable1

DATA TIME DATATYPE :

Date: Format is yyyy-mm=dd

Time: is hh-mm-ss

Datetime: is yyyy-mm-dd hh-mm-ss


Create table Emp (Empno int,HireDate datetime)
Insert into Emp Values (1001,'01/01/78')
Insert into Emp Values (1002,'01/01/78')
Insert into Emp Values (1003,'01/01/78’)
Insert into Emp Values (1004,'01/01/78')
Insert into Emp Values (1005,'02/04/79')

We have predefine getdate() function which gets the current date and time

Image datatype stores only the path of image..

REAL and FLOAT:


Real and float data type takes both int values and decimal values

Insert into tbl values(12)


Or
Insert into tbl values(12.23)
o/p is 12 and 12.23

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.

create table ty (id binary(12))


insert into ty values(467)

select * from ty

o/p is 0x00000000000000000000002B

MONEY:
Its used to store currency values...

Create table Emp (Sal Money, Comm Money)

Insert into Emp Values (4000,345)


Insert into Emp Values (3500,3554)
Insert into Emp Values (4000,4545)
Insert into Emp Values (3000,4545)

You might also like