The DATALENGTH (ColumnName) function will help. It returns the data length in bytes.
Request -
SELECT COLUMN_NAME, DATALENGTH(COLUMN_NAME) as DataSize from information_schema.columns where table_name = 'MyTableName'
This works, but I don't know if there are any pitfalls in this approach.
The maximum size of one table row is
SELECT SUM(DataSize) AS MaxRowSize FROM ( SELECT COLUMN_NAME, DATALENGTH(COLUMN_NAME) as DataSize from information_schema.columns where table_name = 'shop' ) AS SCHEM
The maximum size of the dataset that interests you is
DECLARE @maxRowSize int SET @maxRowSize = ( SELECT SUM(DataSize) AS MaxRowSize FROM ( SELECT COLUMN_NAME, DATALENGTH(COLUMN_NAME) as DataSize from information_schema.columns where table_name = 'shop'
Information about the scheme of the table stores -
COLUMN_NAME DataSize id 4 date 8 sales 10
Test Example with AdventureWorks2008R2 Database -
Save the query results in a text file. See Text File Size. If this is approximately equal to the value returned by my request, then I think we should be good to go.
select * from person.Person where FirstName = 'crystal'
File: Size = 15.2 KB Request: 6116 bytes
Result - does not work for this table! : (
Test 2 -
Salary table -
[id] [int], [name] [varchar](50), [salary] [decimal](18, 2)
Table -
id name salary 1 azamat bagatov 100.50 2 borat 25.00 3 coci buchek 200.50
File: Size = 65 bytes Request: Size = 72 bytes.
Result - Great Success