Thursday, February 16, 2012
Calculating the size of a table in a db
then calculate the size all the tables. If you have 1 table with say 10 rows and 3 columns and the width of the
columns are of variable length you could do something like
( column1width + column2width + column3width ) * No.of Rows = Tablesize
So my question is can I reference the column width of different columns in a
table using sql ?
Another issue is that some of the columns are different datatypes so I should be taking that
into consideration as well.
From searching the internet so far I have seen little on SQL showing how to
reference column width in a table.read about sp_spaceused in Books online|||Yes sp_spaceused is the way to go else see Estimating the Size of a Table (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/createdb/cm_8_des_02_92k3.asp) in Books online|||If you have 1 table with say 10 rows and 3 columns and the width of the
columns are of variable length you could do something like
( column1width + column2width + column3width ) * No.of Rows = Tablesize
In addition to the above comments (and it is clear if you read one of the links) this is wrong. For variable length columns the size if dependent on their contents.
So my question is can I reference the column width of different columns in a
table using sql ?
have a look at INFORMATION_SCHEMA.COLUMNS|||Ya sp_spaceused is good but is there a way I can get a breakdown of how much space is being taken up by each table in the database.
So my Database object is called DBStore and it contains tables
Table1
Table2
Table3 etc... It would be great if I could see what stats on each table...
This is the query that I have used myself but I'm not sure if it works because some of the tables that have 0 rows are saying that there is data in them.
See what you guys think anyway ? Look forward to your feedback ?
select a.name as "NAME",a.xtype as "XTYPE", sum(b.length) * count(*) as "TABLE SIZE"
from sysobjects a, syscolumns b, systypes c
where a.id=b.id -- Table ID = Column ID
and b.xtype = c.xtype
and a.name like '%'
and a.xtype = 'U'
group by a.name,a.xtype
order by "TABLE SIZE";|||select the database then use view-> Taskpad in sql enterprise manager. Then it will list out the space occuoied by each table in your database.
Calculating table size
I have a BIG database with 8 tables growing rapidly. I would like to estimate the size of a row in disk space so I can predict how big my bd will grow in time. I know the math to calculate this but I'm look for a tool to automate this task. A tool that takes into accout calculating index size aside from table size.
I would really apreciate any help on this.
regards
? Since you already have the tables, with rows of real data, I think you can do better than an estimation tool. Take the current table size: EXEC sp_spaceused 'yourTable' ... then get the number of rows: SELECT COUNT(*) FROM yourTable ... and divide. This will give you a much more realistic estimate than any tool can. -- Adam MachanicPro SQL Server 2005, available nowhttp://www..apress.com/book/bookDisplay.html?bID=457-- <Jorge González@.discussions.microsoft.com> wrote in message news:acc81bad-c554-4d2b-8289-fb1482786568@.discussions.microsoft.com... I have a BIG database with 8 tables growing rapidly. I would like to estimate the size of a row in disk space so I can predict how big my bd will grow in time. I know the math to calculate this but I'm look for a tool to automate this task. A tool that takes into accout calculating index size aside from table size. I would really apreciate any help on this. regards|||The Disk Usage report in SQL Server Management Studio shows you the current size of your database breaking down the statistics by table, row size, index, partitions, etc.
I'm putting together a blog series on Management Studio reports. In the first post, I put together a 2 minute demo of how to view the reports and export them to Microsoft Excel 2007.
http://blogs.msdn.com/sqlrem/archive/2006/05/16/SSMS_Reports_1.aspx
-Paul
|||? Hi Paul, I'll check out your webcast, but I'd just like to give a bit of feedback on the reports themselves. Although I really love the look and feel and depth of content of these reports, I find that they're too heavy to run on a busy production server -- especially one with a lot of databases and/or a lot of tables. Would it be possible to modify the reports for a future release such that the drill-down data is "lazy loaded" on demand? This would make the reports a lot more useable for enterprise scenarios. -- Adam MachanicPro SQL Server 2005, available nowhttp://www..apress.com/book/bookDisplay.html?bID=457-- <Paul Mestemaker - MSFT@.discussions.microsoft..com> wrote in message news:7fb4862e-7192-496e-b484-e1547a88728d@.discussions.microsoft.com... The Disk Usage report in SQL Server Management Studio shows you the current size of your database breaking down the statistics by table, row size, index, partitions, etc. I'm putting together a blog series on Management Studio reports. In the first post, I put together a 2 minute demo of how to view the reports and export them to Microsoft Excel 2007. http://blogs.msdn.com/sqlrem/archive/2006/05/16/SSMS_Reports_1.aspx -Paul|||I apologize for the delay in response, I have not setup the alerts properly.
We are somewhat limited in how we can load data into the ReportViewer control in Management Studio. There are two ways the control supports an interactive experience.
Drill-inThis is what we do today. We load in all of the data we need to render the report and show/hide information giving a simulated interactive experience.
|||
Hi Jorge,
You can try the following script on SQL 2000 / 2005
CREATE TABLE #SpaceUsed (name sysname,rows bigint,reserved sysname,data sysname,index_size sysname,unused sysname)
DECLARE @.Counter int
DECLARE @.Max int
DECLARE @.Table sysname
SELECT name, IDENTITY(int,1,1) ROWID
INTO #TableCollection
FROM sysobjects
WHERE xtype = 'U'
ORDER BY lower(name)
SET @.Counter = 1
SET @.Max = (SELECT Max(ROWID) FROM #TableCollection)
WHILE (@.Counter <= @.Max)
BEGIN
SET @.Table = (SELECT name FROM #TableCollection WHERE ROWID = @.Counter)
INSERT INTO #SpaceUsed
EXECUTE sp_spaceused @.Table
SET @.Counter = @.Counter + 1
END
SELECT * FROM #SpaceUsed
DROP TABLE #TableCollection
DROP TABLE #SpaceUsed
Regards
Calculating table size
I have a BIG database with 8 tables growing rapidly. I would like to estimate the size of a row in disk space so I can predict how big my bd will grow in time. I know the math to calculate this but I'm look for a tool to automate this task. A tool that takes into accout calculating index size aside from table size.
I would really apreciate any help on this.
regards
? Since you already have the tables, with rows of real data, I think you can do better than an estimation tool. Take the current table size: EXEC sp_spaceused 'yourTable' ... then get the number of rows: SELECT COUNT(*) FROM yourTable ... and divide. This will give you a much more realistic estimate than any tool can. -- Adam MachanicPro SQL Server 2005, available nowhttp://www..apress.com/book/bookDisplay.html?bID=457-- <Jorge González@.discussions.microsoft.com> wrote in message news:acc81bad-c554-4d2b-8289-fb1482786568@.discussions.microsoft.com... I have a BIG database with 8 tables growing rapidly. I would like to estimate the size of a row in disk space so I can predict how big my bd will grow in time. I know the math to calculate this but I'm look for a tool to automate this task. A tool that takes into accout calculating index size aside from table size. I would really apreciate any help on this. regards|||The Disk Usage report in SQL Server Management Studio shows you the current size of your database breaking down the statistics by table, row size, index, partitions, etc.
I'm putting together a blog series on Management Studio reports. In the first post, I put together a 2 minute demo of how to view the reports and export them to Microsoft Excel 2007.
http://blogs.msdn.com/sqlrem/archive/2006/05/16/SSMS_Reports_1.aspx
-Paul
|||? Hi Paul, I'll check out your webcast, but I'd just like to give a bit of feedback on the reports themselves. Although I really love the look and feel and depth of content of these reports, I find that they're too heavy to run on a busy production server -- especially one with a lot of databases and/or a lot of tables. Would it be possible to modify the reports for a future release such that the drill-down data is "lazy loaded" on demand? This would make the reports a lot more useable for enterprise scenarios. -- Adam MachanicPro SQL Server 2005, available nowhttp://www..apress.com/book/bookDisplay.html?bID=457-- <Paul Mestemaker - MSFT@.discussions.microsoft..com> wrote in message news:7fb4862e-7192-496e-b484-e1547a88728d@.discussions.microsoft.com... The Disk Usage report in SQL Server Management Studio shows you the current size of your database breaking down the statistics by table, row size, index, partitions, etc. I'm putting together a blog series on Management Studio reports. In the first post, I put together a 2 minute demo of how to view the reports and export them to Microsoft Excel 2007. http://blogs.msdn.com/sqlrem/archive/2006/05/16/SSMS_Reports_1.aspx -Paul|||I apologize for the delay in response, I have not setup the alerts properly.
We are somewhat limited in how we can load data into the ReportViewer control in Management Studio. There are two ways the control supports an interactive experience.
Drill-inThis is what we do today. We load in all of the data we need to render the report and show/hide information giving a simulated interactive experience.
|||
Hi Jorge,
You can try the following script on SQL 2000 / 2005
CREATE TABLE #SpaceUsed (name sysname,rows bigint,reserved sysname,data sysname,index_size sysname,unused sysname)
DECLARE @.Counter int
DECLARE @.Max int
DECLARE @.Table sysname
SELECT name, IDENTITY(int,1,1) ROWID
INTO #TableCollection
FROM sysobjects
WHERE xtype = 'U'
ORDER BY lower(name)
SET @.Counter = 1
SET @.Max = (SELECT Max(ROWID) FROM #TableCollection)
WHILE (@.Counter <= @.Max)
BEGIN
SET @.Table = (SELECT name FROM #TableCollection WHERE ROWID = @.Counter)
INSERT INTO #SpaceUsed
EXECUTE sp_spaceused @.Table
SET @.Counter = @.Counter + 1
END
SELECT * FROM #SpaceUsed
DROP TABLE #TableCollection
DROP TABLE #SpaceUsed
Regards
Tuesday, February 14, 2012
Calculating space
Problem - I want to create a query that give me this results
Table, Column , Datatype, Rowcount, Size.
I have a question though, I've read in BOL about how to calculate space
based on variable and fixed lengths of datatypes. What I am not sure about i
s
how to sql allocate space.
Let's say I have a nvarchar(10) column, this is variable length and size
will be the amount of characters entered times two.
For the fixed lenght nchar(n) BOL specify the storage size will be two times
n bytes and one time when working with char.
However in nchar or char, does this mean the size is used even if the actual
char in the field is only 1 out of the 10 characters ?
Char doesn't specify "amount of characters entered" like varchar.
Can someone please help me out with info or a link.
Thanks in advanceFor character type columns the number of bytes they take up on disk is
calculated as follows:
2 bytes if it is variable length (to store the offset in the row)
+ (length for fixed length column or actual data length for variable length
column) * (2 if n(var)char or 1 if (var)char)
You can get the values for the actual number of bytes a column takes up in a
row with the DATALENGTH function. (The result doesn't include the 2 bytes to
store the variable length offset, as that is contributed to row overhead
rather than the column length).
Jacco Schalkwijk
SQL Server MVP
"Mal .mullerjannie@.hotmail.com>" <<removethis> wrote in message
news:80A0E3A9-EA58-49A7-B802-A1FDEA70D092@.microsoft.com...
> Hi
> Problem - I want to create a query that give me this results
> Table, Column , Datatype, Rowcount, Size.
> I have a question though, I've read in BOL about how to calculate space
> based on variable and fixed lengths of datatypes. What I am not sure about
> is
> how to sql allocate space.
> Let's say I have a nvarchar(10) column, this is variable length and size
> will be the amount of characters entered times two.
> For the fixed lenght nchar(n) BOL specify the storage size will be two
> times
> n bytes and one time when working with char.
> However in nchar or char, does this mean the size is used even if the
> actual
> char in the field is only 1 out of the 10 characters ?
> Char doesn't specify "amount of characters entered" like varchar.
> Can someone please help me out with info or a link.
> Thanks in advance
>|||Always specify the size, never leave it to the default. With Char and NChar
datatypes the value stored in the database is always the full size that you
specified since it will padd with spaces. For instance if you have a
CHAR(10) and enter 'xyz' it will still be 10 bytes long and converts to 'xyz
'.
Andrew J. Kelly SQL MVP
"Mal .mullerjannie@.hotmail.com>" <<removethis> wrote in message
news:80A0E3A9-EA58-49A7-B802-A1FDEA70D092@.microsoft.com...
> Hi
> Problem - I want to create a query that give me this results
> Table, Column , Datatype, Rowcount, Size.
> I have a question though, I've read in BOL about how to calculate space
> based on variable and fixed lengths of datatypes. What I am not sure about
> is
> how to sql allocate space.
> Let's say I have a nvarchar(10) column, this is variable length and size
> will be the amount of characters entered times two.
> For the fixed lenght nchar(n) BOL specify the storage size will be two
> times
> n bytes and one time when working with char.
> However in nchar or char, does this mean the size is used even if the
> actual
> char in the field is only 1 out of the 10 characters ?
> Char doesn't specify "amount of characters entered" like varchar.
> Can someone please help me out with info or a link.
> Thanks in advance
>
Calculating Snapshot Folder Size Needed
Just wondering if there are any formulas for calculating the snapshot folder
size?
Thanks,
Michael
No, due to fragmentation of tables your snapshots can be smaller than the
database itself.
Hilary Cotter
Director of Text Mining and Database Strategy
RelevantNOISE.Com - Dedicated to mining blogs for business intelligence.
This posting is my own and doesn't necessarily represent RelevantNoise's
positions, strategies or opinions.
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"Batman" <Batman@.discussions.microsoft.com> wrote in message
news:2D836F5F-5D17-4EAA-805A-1EE1DD2074E4@.microsoft.com...
> Hello all,
> Just wondering if there are any formulas for calculating the snapshot
> folder
> size?
> Thanks,
> Michael
Calculating Row Size including blobs
usually in the processing of planning for server storage needs.
Well, I've got a different problem. I need to know how much data each
of our Customers are using in a Database. (1 SQL DB stores multiple
customers).
Basically, I want to be able to say: Customer A: 45.5 MB, Customer B:
655 MB.
So, how can I ask SQL Server how much data each Row in each table is
taking up? I want to be able to calculate nightly the total size, so I
would take each row in each table that belong to the customer, and add
all the sizes together. I want to take into account blobs that are
storing images and PDF files also.
Thanks in advance,
Jesse Wolgamott[posted and mailed, please reply in news]
Jesse Wolgamott (jesse.wolgamott@.gmail.com) writes:
> I've seen plenty of posts regarding the estimation of table size,
> usually in the processing of planning for server storage needs.
> Well, I've got a different problem. I need to know how much data each
> of our Customers are using in a Database. (1 SQL DB stores multiple
> customers).
> Basically, I want to be able to say: Customer A: 45.5 MB, Customer B:
> 655 MB.
> So, how can I ask SQL Server how much data each Row in each table is
> taking up? I want to be able to calculate nightly the total size, so I
> would take each row in each table that belong to the customer, and add
> all the sizes together. I want to take into account blobs that are
> storing images and PDF files also.
This is not a problem with a clearcut answer, since if a table gets
fragmented, that extra space is not really any particular customer,
but presumably someone should be accounted for it.
Therefore I would for the non-blob data take the number of rows for
each customer and scale that with the number of rows for each customer.
For the blob data I would simply sum the sizes of each field:
SELECT t.CustomerID,
MB = ((1E0 * COUNT(*) * i.reserved / i.rows) * 8192 +
SUM(coalesce(datalength(t.blobcol), 0)) / 1E6
FROM tbl t
CROSS JOIN sysindexes i
WHERE i.id = object_id('tbl')
AND i.indid IN (0, 1)
GROUP BY t.CustomerID
You should run DBCC UPDATEUSAGE on the database prior to running this-
The result will be skewed if you have tables with long non-blob
character/binary columns where different customer have very differing
average length on these columns. Also, if you are using the "text in row",
customers with small blobs may be accounted twice for the same thing.
--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp
Calculating Row Size
1. Why is the size of a table reported by Enterprise Manager in Table Info
so different than the size that is returned when using sp_spaceused?
2. I've found the calculations but was wondering if there exists a system
stored procedure that would return the size of a row in a table? For example
,
I'm looking to capture the max, min, and avg size of a row in a particular
table.
Any input is greatly appreciated!
Thanks!1. I don't know. Sorry!
2. No, but you could do this to get the information you want
CREATE TABLE ColumnSizes (table_name varchar(50), column_name varchar(50),
min_size int, max_size int)
GO
DECLARE @.table_name varchar(100)
DECLARE @.column_name varchar(100)
DECLARE @.querystring nvarchar(1000)
SET @.querystring = ''
DECLARE columns_cursor CURSOR STATIC FORWARD_ONLY
FOR
SELECT t1.table_name, t2.column_name
FROM INFORMATION_SCHEMA.TABLES t1
INNER JOIN INFORMATION_SCHEMA.COLUMNS t2
ON t1.table_name = t2.table_name
WHERE t1.table_type = 'BASE TABLE' AND t1.table_name <> 'columnsizes'
OPEN columns_cursor
FETCH NEXT FROM columns_cursor INTO @.table_name, @.column_name
WHILE (@.@.FETCH_STATUS = 0)
BEGIN
SET @.querystring = 'INSERT INTO ColumnSizes SELECT ''' + @.table_name +
''', ''' +
@.column_name + ''', MIN(DATALENGTH([' + @.column_name + '])),
MAX(DATALENGTH([' +
@.column_name + '])) FROM [' + @.table_name + ']'
--PRINT @.querystring
EXEC sp_executesql @.querystring
FETCH NEXT FROM columns_cursor INTO @.table_name, @.column_name
END
CLOSE columns_cursor
DEALLOCATE columns_cursor
select * from columnsizes
"A. Robinson" wrote:
> A couple of questions regading table size:
> 1. Why is the size of a table reported by Enterprise Manager in Table Info
> so different than the size that is returned when using sp_spaceused?
> 2. I've found the calculations but was wondering if there exists a system
> stored procedure that would return the size of a row in a table? For examp
le,
> I'm looking to capture the max, min, and avg size of a row in a particular
> table.
> Any input is greatly appreciated!
> Thanks!|||Thanks!!
One quick question:
The database I'm running this against has 4500+ attributes/columns. I
started running the procedure last night and left for the evening. When I go
t
back in, it was still running - 18+ hours...
Is that normal?!?
Thanks!!
"Mark Williams" wrote:
> 1. I don't know. Sorry!
> 2. No, but you could do this to get the information you want
> CREATE TABLE ColumnSizes (table_name varchar(50), column_name varchar(50),
> min_size int, max_size int)
> GO
> DECLARE @.table_name varchar(100)
> DECLARE @.column_name varchar(100)
> DECLARE @.querystring nvarchar(1000)
> SET @.querystring = ''
> DECLARE columns_cursor CURSOR STATIC FORWARD_ONLY
> FOR
> SELECT t1.table_name, t2.column_name
> FROM INFORMATION_SCHEMA.TABLES t1
> INNER JOIN INFORMATION_SCHEMA.COLUMNS t2
> ON t1.table_name = t2.table_name
> WHERE t1.table_type = 'BASE TABLE' AND t1.table_name <> 'columnsizes'
> OPEN columns_cursor
> FETCH NEXT FROM columns_cursor INTO @.table_name, @.column_name
> WHILE (@.@.FETCH_STATUS = 0)
> BEGIN
> SET @.querystring = 'INSERT INTO ColumnSizes SELECT ''' + @.table_name +
> ''', ''' +
> @.column_name + ''', MIN(DATALENGTH([' + @.column_name + '])),
> MAX(DATALENGTH([' +
> @.column_name + '])) FROM [' + @.table_name + ']'
> --PRINT @.querystring
> EXEC sp_executesql @.querystring
> FETCH NEXT FROM columns_cursor INTO @.table_name, @.column_name
> END
> CLOSE columns_cursor
> DEALLOCATE columns_cursor
> select * from columnsizes
>
> --
>
> "A. Robinson" wrote:
>|||On Fri, 27 Jan 2006 09:00:03 -0800, A. Robinson wrote:
>Thanks!!
>One quick question:
>The database I'm running this against has 4500+ attributes/columns. I
>started running the procedure last night and left for the evening. When I g
ot
>back in, it was still running - 18+ hours...
>Is that normal?!?
Hi A.,
I just checked the script Mark posted, and I'm not surprised.
For each column, a query is executed to find MIN(DATALENGTH(column)) and
MAX(DATALENGTH(column)). That requires a full table scan for each
column. So if you have a 100 million row table with 40 columns, the 100
million rows will be scanned 40 times.
Hugo Kornelis, SQL Server MVP|||I didn't consider a database that large. (I live in my own little world with
little databases).
Other than adding WITH (NOLOCK) to the select statement, I can't think of
much else to modify the script as is. In reality, my script really didn't ge
t
what you wanted, which was the minimum and maximum size of a row in a table.
I gave you the minimum and maximum sizes of columns in the tables. Since
physical storage sizes for most of the datatypes are fixed (ie int, datetime
,
smalldatetime, ..) it would probably be better to only run the SELECT
MAX(DATELENGTH()), MIN(DATALENGTH()) statement on columns that had variable
physical size data capabilities (ie varchar,nvarchar,text,ntext, and so on).
Unfortunately, I can't whip that one up right now, but I will work on it and
post it here.|||an obvious optimization would be to issue one select per table, not one
per column. naturally that would require more complex programming.
makes sense?|||an obvious optimization would be to issue one select per table, not one
per column. naturally that would require more complex programming.
makes sense?|||Give this a try. The whole thing takes about 3 seconds for Northwind
It runs through a set of nested cursors for only the variable length
datatypes, then joins the output table with information_schema.columns to ge
t
the totals with the fixed length datatypes.
drop table variablerowsizes
go
CREATE TABLE VariableRowSizes (table_name varchar(50), min_size int,
max_size int, avgsize int)
GO
DECLARE @.table_name nvarchar(100)
DECLARE @.column_name nvarchar(100)
DECLARE @.column_list nvarchar(4000)
DECLARE @.querystring nvarchar(4000)
SET @.querystring = ''
set @.column_list = ''
DECLARE tables_cursor CURSOR STATIC FORWARD_ONLY
FOR
select distinct t1.table_name
from information_schema.tables t1
inner join information_schema.columns t2
on t1.table_name = t2.table_name
where t1.table_type = 'BASE TABLE'
and t2.data_type in
('varchar','nvarchar','text','ntext','va
rbinary','image','sql_variant')
order by t1.table_name
OPEN tables_cursor
FETCH NEXT FROM tables_cursor INTO @.table_name
WHILE (@.@.FETCH_STATUS = 0)
BEGIN
set @.querystring = ''
set @.column_list = ''
declare columns_cursor cursor static forward_only
for
select distinct column_name
from information_schema.columns
where table_name = @.table_name
and data_type in
('varchar','nvarchar','text','ntext','va
rbinary','image','sql_variant')
open columns_cursor
fetch next from columns_cursor into @.column_name
WHILE (@.@.FETCH_STATUS = 0)
begin
set @.column_list = @.column_list + N'DATALENGTH([' + @.column_name + N'])
+ '
fetch next from columns_cursor into @.column_name
end
close columns_cursor
deallocate columns_cursor
set @.column_list = SUBSTRING(@.column_list,1,LEN(@.column_lis
t) - 2)
set @.querystring = N'insert into variablerowsizes select '''
+ @.table_name + N''', min(' + @.column_list + N'), max(' + @.column_list
+ N'), avg(' + @.column_list
+ N') from ' + @.table_name
--print @.querystring
EXEC sp_executesql @.querystring
FETCH NEXT FROM tables_cursor INTO @.table_name
END
CLOSE tables_cursor
DEALLOCATE tables_cursor
select t3.table_name, t3.[fixed column sizes] + isnull(t4.[bit sizes],0) +
isnull(t5.min_size,0) AS "minimum row size",
t3.[fixed column sizes] + isnull(t4.[bit sizes],0) + isnull(t5.max_size,0)
AS "maximum row size",
t3.[fixed column sizes] + isnull(t4.[bit sizes],0) + isnull(t5.avgsize,0) AS
"average row size"
from (
select t1.table_name,
sum(
case
when t2.data_type = 'uniqueidentifier' then 16
when t2.data_type in ('char','nchar') then t2.character_octet_length
when t2.data_type in ('bigint','money','datetime','timestamp'
) then 8
when t2.data_type in ('int','smallmoney','smalldatetime','rea
l') then 4
when t2.data_type = 'smallint' then 2
when t2.data_type = 'tinyint' then 1
when t2.data_type in ('decimal','numeric') then
case
when t2.numeric_precision between 1 and 9 then 5
when t2.numeric_precision between 10 and 19 then 9
when t2.numeric_precision between 20 and 28 then 13
else 17
end
when t2.data_type = 'float' then
case
when t2.numeric_precision between 1 and 24 then 4
else 8
end
when t2.data_type = 'binary' then t2.character_octet_length + 4
else 0
end) as "fixed column sizes"
from information_schema.tables t1 left join information_schema.columns t2
on t1.table_name = t2.table_name
where t1.table_type = 'BASE TABLE'
group by t1.table_name
) t3 left join
(
select t1.table_name, ((count(t2.data_type) - 1) / 8) + 1 as "bit sizes"
from information_schema.tables t1
left join information_schema.columns t2
on t1.table_name = t2.table_name
where t1.table_type = 'BASE TABLE'
and t2.data_type = 'bit'
group by t1.table_name
) t4 on t3.table_name = t4.table_name
left join variablerowsizes t5
on t3.table_name = t5.table_name
"A. Robinson" wrote:
> A couple of questions regading table size:
> 1. Why is the size of a table reported by Enterprise Manager in Table Info
> so different than the size that is returned when using sp_spaceused?
> 2. I've found the calculations but was wondering if there exists a system
> stored procedure that would return the size of a row in a table? For examp
le,
> I'm looking to capture the max, min, and avg size of a row in a particular
> table.
> Any input is greatly appreciated!
> Thanks!
Calculating number of Bytes
We are trying to get a rough estimate of the size of the warehouse in terms of number of bytes. Now I understand that when I say char(2) datatype requires 2 bytes of memory. If this is correct then how many bytes does the following data type need -
1. smalldatetime
2. decimal(14,2)
3. decimal(12,2)
4. int
5. smallint.
6. decimal(9,0)
Also can you explain the byte allocation for a varchar column. Say varchar(20) for example.
Any help is appreciated.
VivekAll of the gory details are explained in Inside SQL Server 2000 (http://search.barnesandnoble.com/booksearch/isbnInquiry.asp?userid=bsq1M1M1GT&isbn=0735609985&itm=1) by Kalen Delaney. Once you read her chapter on table structures, you'll be able to compute exactly how much space your data will need. After you read the chapter on indexing, you'll understand exactly how much space your indicies will need. At that point, you'll also understand more than about 80% of the SQL Server users wandering the planet!
Just as a disclaimer: Kalen is an old friend of mine, but I have no interest of any kind (particularly financial) in selling her book.
-PatP|||Who says indicies?|||Who says indicies?Me do. Why?
-PatP
Calculating initial size tempdb
(this is on a production server), I am aware from the reading I have done,
that it may be possible to increase performance if the initial size of the
log is adequate to prevent the tempdb from performing a great deal of
autogrowth [viewable in the dbcc loginfo('mydb') command]. Is there a
formula to calculate approximately what this initial size should be set at?
Do I risk hurting performance if this is done incorrectly? Currently there
is plenty of disk space available but we are considering log shipping which
will substantially reduce that space. The log file for the very large
database tends to hover around 10 gig which seems fairly large to me, but
considering there is a history filegroup that hovers around 55 gig and a
primary filegroup around 35 gig, it may be correct.
I am looking for some general guidance on how to set the tempdb initial
size for greater performance and perhaps how to fix log files that are
disporportionately large resulting from constant bulk inserts. Two sites I
looked at
http://www.karaszi.com/SQLServer/info_dont_shrink.asp
and
http://sqlserver2000.databases.aspfaq.com/why-is-tempdb-full-and-how-can-i-prevent-this-from-happening.html
have pushed me to inquire in this fashion.
Regards,
Jamie
Correction to the above. The test database indicates that the initial size
should be about 400 MB if it is to be larger than the one currently there.
I have set the initial size to 400 MB. Is there a way to test this size?
Regards,
Jamie
"thejamie" wrote:
> Although I may not be sure I know how to set the initial size of the tempdb
> (this is on a production server), I am aware from the reading I have done,
> that it may be possible to increase performance if the initial size of the
> log is adequate to prevent the tempdb from performing a great deal of
> autogrowth [viewable in the dbcc loginfo('mydb') command]. Is there a
> formula to calculate approximately what this initial size should be set at?
> Do I risk hurting performance if this is done incorrectly? Currently there
> is plenty of disk space available but we are considering log shipping which
> will substantially reduce that space. The log file for the very large
> database tends to hover around 10 gig which seems fairly large to me, but
> considering there is a history filegroup that hovers around 55 gig and a
> primary filegroup around 35 gig, it may be correct.
> I am looking for some general guidance on how to set the tempdb initial
> size for greater performance and perhaps how to fix log files that are
> disporportionately large resulting from constant bulk inserts. Two sites I
> looked at
> http://www.karaszi.com/SQLServer/info_dont_shrink.asp
> and
>
> http://sqlserver2000.databases.aspfaq.com/why-is-tempdb-full-and-how-can-i-prevent-this-from-happening.html
> have pushed me to inquire in this fashion.
> --
> Regards,
> Jamie
|||Hi Jamie
I am not sure there is a formula that tells you a figure that you can set
tempdb to to get the size. There are separate ones for things like how much
space would be used by rebuilding indexes
http://msdn2.microsoft.com/en-us/library/ms191183.aspx. In general I would
look at setting a reasonable size and then monitoring when and by how much it
grows. Then setting the initial size to a value that will cover normal usage.
John
"thejamie" wrote:
[vbcol=seagreen]
> Correction to the above. The test database indicates that the initial size
> should be about 400 MB if it is to be larger than the one currently there.
> I have set the initial size to 400 MB. Is there a way to test this size?
> --
> Regards,
> Jamie
>
> "thejamie" wrote:
Calculating initial size tempdb
(this is on a production server), I am aware from the reading I have done,
that it may be possible to increase performance if the initial size of the
log is adequate to prevent the tempdb from performing a great deal of
autogrowth [viewable in the dbcc loginfo('mydb') command]. Is there a
formula to calculate approximately what this initial size should be set at?
Do I risk hurting performance if this is done incorrectly? Currently there
is plenty of disk space available but we are considering log shipping which
will substantially reduce that space. The log file for the very large
database tends to hover around 10 gig which seems fairly large to me, but
considering there is a history filegroup that hovers around 55 gig and a
primary filegroup around 35 gig, it may be correct.
I am looking for some general guidance on how to set the tempdb initial
size for greater performance and perhaps how to fix log files that are
disporportionately large resulting from constant bulk inserts. Two sites I
looked at
http://www.karaszi.com/SQLServer/info_dont_shrink.asp
and
http://sqlserver2000.databases.aspf...-happening.html
have pushed me to inquire in this fashion.
Regards,
JamieCorrection to the above. The test database indicates that the initial size
should be about 400 MB if it is to be larger than the one currently there.
I have set the initial size to 400 MB. Is there a way to test this size?
--
Regards,
Jamie
"thejamie" wrote:
> Although I may not be sure I know how to set the initial size of the tempd
b
> (this is on a production server), I am aware from the reading I have done,
> that it may be possible to increase performance if the initial size of the
> log is adequate to prevent the tempdb from performing a great deal of
> autogrowth [viewable in the dbcc loginfo('mydb') command]. Is there
a
> formula to calculate approximately what this initial size should be set at
?
> Do I risk hurting performance if this is done incorrectly? Currently ther
e
> is plenty of disk space available but we are considering log shipping whic
h
> will substantially reduce that space. The log file for the very large
> database tends to hover around 10 gig which seems fairly large to me, but
> considering there is a history filegroup that hovers around 55 gig and a
> primary filegroup around 35 gig, it may be correct.
> I am looking for some general guidance on how to set the tempdb initial
> size for greater performance and perhaps how to fix log files that are
> disporportionately large resulting from constant bulk inserts. Two sites
I
> looked at
> http://www.karaszi.com/SQLServer/info_dont_shrink.asp
> and
>
> http://sqlserver2000.databases.aspf...-happening.html
> have pushed me to inquire in this fashion.
> --
> Regards,
> Jamie|||Hi Jamie
I am not sure there is a formula that tells you a figure that you can set
tempdb to to get the size. There are separate ones for things like how much
space would be used by rebuilding indexes
http://msdn2.microsoft.com/en-us/library/ms191183.aspx. In general I would
look at setting a reasonable size and then monitoring when and by how much i
t
grows. Then setting the initial size to a value that will cover normal usage
.
John
"thejamie" wrote:
[vbcol=seagreen]
> Correction to the above. The test database indicates that the initial siz
e
> should be about 400 MB if it is to be larger than the one currently there.
> I have set the initial size to 400 MB. Is there a way to test this size?
> --
> Regards,
> Jamie
>
> "thejamie" wrote:
>
Sunday, February 12, 2012
Calculating Folder Size in TSQL
a stored procedure/function.
Basically, I want to do a select on a table, grab all data from the
table and get the size of a directory for each record. The select
would look something like this...
SELECT
w.WebsiteName,
w.IPAddress,
w.Status,
c.ClientName,
dbo.udfGetFolderSize(w.WebsitePath) as FolderSize -- <-- This is
what I am looking for...
FROM dbo.Websites w
INNER JOIN dbo.Clients c
ON c.ID = w.Clients_ID
ORDER BY w.WebsiteName, C.ClientNameHi,
I'm doing something similar with the DOS dir command and xp_cmdshell, though
I'm looking for files, not total usage.
Here is a small example to get you started.
Good luck,
Jay
-- cut --
use tempdb
set nocount on
declare @.line varchar(255)
declare @.path varchar(255)
declare @.command varchar(255)
if object_id('#output') is not null and objectproperty(object_id('#output'),
'IsTable') = 1
drop table #output
create table #output (line varchar(255))
set @.path = 'C:\Program Files'
set @.path = 'C:\WINDOWS'
set @.command = 'dir "' + @.path +'"'
insert into #output
exec master.dbo.xp_cmdshell @.command
select @.line = ltrim(replace(substring(line, charindex(')', line)+1,
len(line)), ',', ''))
from #output where line like '%File(s)%bytes'
print @.line + ' (This is a string and the value ignores the size of any
sub-folders)'
-- cut --
<TampaWebDevelopment@.gmail.com> wrote in message
news:1192614500.170755.290550@.q3g2000prf.googlegroups.com...
>I am looking for a method to calculate the size of a directory within
> a stored procedure/function.
> Basically, I want to do a select on a table, grab all data from the
> table and get the size of a directory for each record. The select
> would look something like this...
> SELECT
> w.WebsiteName,
> w.IPAddress,
> w.Status,
> c.ClientName,
> dbo.udfGetFolderSize(w.WebsitePath) as FolderSize -- <-- This is
> what I am looking for...
> FROM dbo.Websites w
> INNER JOIN dbo.Clients c
> ON c.ID = w.Clients_ID
> ORDER BY w.WebsiteName, C.ClientName
>|||The problem with this is enabling xp_cmdshell which is a potential security
threat. Why not use WMI with VBScript instead, write the results in a CSV
file and import the data in a SQL Server table?
"Jay" <spam@.nospam.org> wrote in message
news:OAfGOXMEIHA.5208@.TK2MSFTNGP04.phx.gbl...
> Hi,
> I'm doing something similar with the DOS dir command and xp_cmdshell,
> though I'm looking for files, not total usage.
> Here is a small example to get you started.
> Good luck,
> Jay
> -- cut --
> use tempdb
> set nocount on
> declare @.line varchar(255)
> declare @.path varchar(255)
> declare @.command varchar(255)
> if object_id('#output') is not null and
> objectproperty(object_id('#output'), 'IsTable') = 1
> drop table #output
> create table #output (line varchar(255))
> set @.path = 'C:\Program Files'
> set @.path = 'C:\WINDOWS'
> set @.command = 'dir "' + @.path +'"'
> insert into #output
> exec master.dbo.xp_cmdshell @.command
> select @.line = ltrim(replace(substring(line, charindex(')', line)+1,
> len(line)), ',', ''))
> from #output where line like '%File(s)%bytes'
> print @.line + ' (This is a string and the value ignores the size of any
> sub-folders)'
> -- cut --
>
> <TampaWebDevelopment@.gmail.com> wrote in message
> news:1192614500.170755.290550@.q3g2000prf.googlegroups.com...
>>I am looking for a method to calculate the size of a directory within
>> a stored procedure/function.
>> Basically, I want to do a select on a table, grab all data from the
>> table and get the size of a directory for each record. The select
>> would look something like this...
>> SELECT
>> w.WebsiteName,
>> w.IPAddress,
>> w.Status,
>> c.ClientName,
>> dbo.udfGetFolderSize(w.WebsitePath) as FolderSize -- <-- This is
>> what I am looking for...
>> FROM dbo.Websites w
>> INNER JOIN dbo.Clients c
>> ON c.ID = w.Clients_ID
>> ORDER BY w.WebsiteName, C.ClientName
>|||He asked for a way from within T-SQL. Can you use WMI from SQL? I didn't
think so.
"bass_player [SBS-MVP]" <bass_player@.mvps.org> wrote in message
news:u2LkjuVEIHA.1208@.TK2MSFTNGP05.phx.gbl...
> The problem with this is enabling xp_cmdshell which is a potential
> security threat. Why not use WMI with VBScript instead, write the results
> in a CSV file and import the data in a SQL Server table?
> "Jay" <spam@.nospam.org> wrote in message
> news:OAfGOXMEIHA.5208@.TK2MSFTNGP04.phx.gbl...
>> Hi,
>> I'm doing something similar with the DOS dir command and xp_cmdshell,
>> though I'm looking for files, not total usage.
>> Here is a small example to get you started.
>> Good luck,
>> Jay
>> -- cut --
>> use tempdb
>> set nocount on
>> declare @.line varchar(255)
>> declare @.path varchar(255)
>> declare @.command varchar(255)
>> if object_id('#output') is not null and
>> objectproperty(object_id('#output'), 'IsTable') = 1
>> drop table #output
>> create table #output (line varchar(255))
>> set @.path = 'C:\Program Files'
>> set @.path = 'C:\WINDOWS'
>> set @.command = 'dir "' + @.path +'"'
>> insert into #output
>> exec master.dbo.xp_cmdshell @.command
>> select @.line = ltrim(replace(substring(line, charindex(')', line)+1,
>> len(line)), ',', ''))
>> from #output where line like '%File(s)%bytes'
>> print @.line + ' (This is a string and the value ignores the size of any
>> sub-folders)'
>> -- cut --
>>
>> <TampaWebDevelopment@.gmail.com> wrote in message
>> news:1192614500.170755.290550@.q3g2000prf.googlegroups.com...
>>I am looking for a method to calculate the size of a directory within
>> a stored procedure/function.
>> Basically, I want to do a select on a table, grab all data from the
>> table and get the size of a directory for each record. The select
>> would look something like this...
>> SELECT
>> w.WebsiteName,
>> w.IPAddress,
>> w.Status,
>> c.ClientName,
>> dbo.udfGetFolderSize(w.WebsitePath) as FolderSize -- <-- This is
>> what I am looking for...
>> FROM dbo.Websites w
>> INNER JOIN dbo.Clients c
>> ON c.ID = w.Clients_ID
>> ORDER BY w.WebsiteName, C.ClientName
>>
>
Calculating database size
I need help . Is anybody can help me to finde transact-SQL code of calculating the database size.
Thanks in advnce , Alexsp_databases