How calculate space that occupied?

How calculate space that occupied?

am 12.06.2007 09:35:23 von k.visube

I want to know following memory space related question.


1 . How can i get a Database Size by means of a SQL query?

2. How can i Get a field size (not allocated space) .. ie. i am
storing some textual data to a field..
after a insertion i want to know how much space has been occupied by
that particular field .

ex sno product_name Description
1 sample1 dfkjsdkfj kldsjfkdjk
sdkjdfskdjk vcmvxcvmcvnksdjfkdsn m

Here i want know the space occupied by the field name "description"
for the product id=1.

Thanks in adavance

Regards
Visu.

Re: How calculate space that occupied?

am 12.06.2007 11:47:38 von masri999

On Jun 12, 12:35 pm, visu wrote:
> I want to know following memory space related question.
>
> 1 . How can i get a Database Size by means of a SQL query?
>
> 2. How can i Get a field size (not allocated space) .. ie. i am
> storing some textual data to a field..
> after a insertion i want to know how much space has been occupied by
> that particular field .
>
> ex sno product_name Description
> 1 sample1 dfkjsdkfj kldsjfkdjk
> sdkjdfskdjk vcmvxcvmcvnksdjfkdsn m
>
> Here i want know the space occupied by the field name "description"
> for the product id=1.
>
> Thanks in adavance
>
> Regards
> Visu.

1. How can i get a Database Size by means of a SQL query

sp_helpdb 'dbname'

2. Here i want know the space occupied by the field name "description"
for the product id=1.

SELECT SUM(DATALENGTH(description)) FROM table
WHERE product_id=1.

Re: How calculate space that occupied?

am 12.06.2007 12:43:26 von undercups

On Jun 12, 10:47 am, M A Srinivas wrote:
> On Jun 12, 12:35 pm, visu wrote:
>
>
>
>
>
> > I want to know following memory space related question.
>
> > 1 . How can i get a Database Size by means of a SQL query?
>
> > 2. How can i Get a field size (not allocated space) .. ie. i am
> > storing some textual data to a field..
> > after a insertion i want to know how much space has been occupied by
> > that particular field .
>
> > ex sno product_name Description
> > 1 sample1 dfkjsdkfj kldsjfkdjk
> > sdkjdfskdjk vcmvxcvmcvnksdjfkdsn m
>
> > Here i want know the space occupied by the field name "description"
> > for the product id=1.
>
> > Thanks in adavance
>
> > Regards
> > Visu.
>
> 1. How can i get a Database Size by means of a SQL query
>
> sp_helpdb 'dbname'
>
> 2. Here i want know the space occupied by the field name "description"
> for the product id=1.
>
> SELECT SUM(DATALENGTH(description)) FROM table
> WHERE product_id=1.- Hide quoted text -
>
> - Show quoted text -

Use the length function

SELECT LENGTH(description) FROM tablename WHERE id = 1

This will return the length of the description field for the row
identified by id = 1.

Re: How calculate space that occupied?

am 12.06.2007 23:31:37 von Erland Sommarskog

undercups (dwang@woodace.co.uk) writes:
> Use the length function
>
> SELECT LENGTH(description) FROM tablename WHERE id = 1
>
> This will return the length of the description field for the row
> identified by id = 1.

There is no LENGTH function in SQL Server.

You may be thinking of len(), but since Visu asked for the space
consumption, it does not fit the bill for two reasons:

1) It ignores trailing spaces.
2) It counts characters, not bytes, which makes a difference for nvarchar.

--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downlo ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books .mspx

Re: How calculate space that occupied?

am 12.06.2007 23:32:32 von Erland Sommarskog

M A Srinivas (masri999@gmail.com) writes:
> 2. Here i want know the space occupied by the field name "description"
> for the product id=1.
>
> SELECT SUM(DATALENGTH(description)) FROM table
> WHERE product_id=1.

Should be:

SELECT SUM(2 + DATALENGTH(description)) FROM table
WHERE product_id=1.

Add 2 for the length stored for the field.

--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downlo ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books .mspx