|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Size of a rowHow can I get (Programatically) the size of a row in a table in SQL stored
procedure? Evan
http://msdn.microsoft.com/library/en-us/createdb/cm_8_des_02_92k3.asp
Show quote "Evan Camilleri" <e7***@yahoo.co.uk.nospam> wrote in message
news:OhDpYh19FHA.2472@TK2MSFTNGP12.phx.gbl... > How can I get (Programatically) the size of a row in a table in SQL stored > procedure? > > Evan > I need a function or whatever to calculate the size since the procedure will
be used on different tables! Evan Show quote "Aaron Bertrand [SQL Server MVP]" <ten.xoc@dnartreb.noraa> wrote in message news:%23%23MlNx19FHA.3560@TK2MSFTNGP12.phx.gbl... > http://msdn.microsoft.com/library/en-us/createdb/cm_8_des_02_92k3.asp > > > "Evan Camilleri" <e7***@yahoo.co.uk.nospam> wrote in message > news:OhDpYh19FHA.2472@TK2MSFTNGP12.phx.gbl... >> How can I get (Programatically) the size of a row in a table in SQL >> stored procedure? >> >> Evan >> > > I found a thread where someone posted a stored procedure for calculating row
size. It accepts @TableName as a parameter and returns @Row_Size as output. http://groups.google.com/group/microsoft.public.sqlserver.programming/browse_thread/thread/3d4e2272f814540d/7f33627d8c355841 Show quote "Evan Camilleri" <e7***@yahoo.co.uk.nospam> wrote in message news:%23QfZxN29FHA.2708@TK2MSFTNGP12.phx.gbl... >I need a function or whatever to calculate the size since the procedure >will be used on different tables! > > Evan > > > "Aaron Bertrand [SQL Server MVP]" <ten.xoc@dnartreb.noraa> wrote in > message news:%23%23MlNx19FHA.3560@TK2MSFTNGP12.phx.gbl... >> http://msdn.microsoft.com/library/en-us/createdb/cm_8_des_02_92k3.asp >> >> >> "Evan Camilleri" <e7***@yahoo.co.uk.nospam> wrote in message >> news:OhDpYh19FHA.2472@TK2MSFTNGP12.phx.gbl... >>> How can I get (Programatically) the size of a row in a table in SQL >>> stored procedure? >>> >>> Evan >>> >> >> > > >I need a function or whatever to calculate the size since the procedure So do you want max possible, max actual, avg possible, avg actual, actual of >will be used on different tables! a random row, ...? > So do you want max possible, max actual, avg possible, avg actual, actual Sorry, avg possible doesn't really make sense, I guess...> of a random row, ...? There are some developers who would spend a week coding a request for
"average possible" before go back and asking the obvious question. Show quote "Aaron Bertrand [SQL Server MVP]" <ten.xoc@dnartreb.noraa> wrote in message news:eeT0$%2329FHA.916@TK2MSFTNGP10.phx.gbl... >> So do you want max possible, max actual, avg possible, avg actual, actual >> of a random row, ...? > > Sorry, avg possible doesn't really make sense, I guess... > > before go back and asking the obvious question. There are a few in this case. Which one do you mean? :-)I want to create a stored proc which returns not more than X kilobytes of
records. Evan Show quote "Aaron Bertrand [SQL Server MVP]" <ten.xoc@dnartreb.noraa> wrote in message news:%23wkxc929FHA.2268@TK2MSFTNGP15.phx.gbl... > >I need a function or whatever to calculate the size since the procedure > >will be used on different tables! > > So do you want max possible, max actual, avg possible, avg actual, actual > of a random row, ...? > This would be a lot more simple if the row only contained non-NULL columns
of fixed width data types (integers, char, datetime, etc.). If it contains any columns of type VarChar or columns of NULL value, then the width of each row will vary significantly. Let's assume that you determine the average row with to be 385 bytes and you want to return only 200KB of data. 200,000 / 385 = ~519 Therefore, your stored procedure would need to use the SELECT TOP ... clause to return the appropriate number of rows. For example: select top 519 from mytable At least in SQL Server 2000, SELECT TOP cannot reference a variable, so you would need to either hard code the number 519 or, if the stored procedure allows specifying the number of KB as a parameter, you will need to first build your select statement in a VarChar string and then execute it using the EXEC command. The following article describes techniques for using dynamic SQL in such a way: http://www.sqlteam.com/item.asp?ItemID=4599 Keep this in mind: If your goal here is to reduce the amount network bandwidth or memory consumption of the dataset, then keep in mind that even though SQL Server may store the data internally using 200 KB, the data's size will be different (probably much more) once converted into XML or an ADO recordset by the middle tier or client application. Show quote "Evan Camilleri" <e7***@yahoo.co.uk.nospam> wrote in message news:up$hDX%239FHA.1032@TK2MSFTNGP11.phx.gbl... >I want to create a stored proc which returns not more than X kilobytes of >records. > > Evan > > > "Aaron Bertrand [SQL Server MVP]" <ten.xoc@dnartreb.noraa> wrote in > message news:%23wkxc929FHA.2268@TK2MSFTNGP15.phx.gbl... >> >I need a function or whatever to calculate the size since the procedure >> >will be used on different tables! >> >> So do you want max possible, max actual, avg possible, avg actual, actual >> of a random row, ...? >> > > |
|||||||||||||||||||||||