Thursday 22 August 2013

Finding Data Size of column in Bytes in SQL SERVER

Returns the number of bytes used to represent any expression.

Here the “datalength “ funcion helps to find the size of the data in the column. For example data in the column is “ARUN” then it takes 4 bytes, because one charater takes one byte, likewise you can calculate for all datatypes.

-- Created table with Primary Key
CREATE TABLE MyOrdersPrimary
(
    OrderId int PRIMARY KEY NOT NULL,
    ProductName varchar(20)
);

-- Inserted some records
insert into MyOrdersPrimary values (1,'Samsung')
insert into MyOrdersPrimary values (2,'Nokia')
select datalength(ProductName) as Bytes, * from MyOrdersPrimary

No comments:

Post a Comment