質問

When I use SQL Server Text or Varchar(max) datatype in a column it creates databases that are too large : for example 1000 rows in one table containing varchar(max) use around 1000 Mb (1Gb) !!!!

Is that normal ?

thanks for help

Edit my text fields are about 5 to 50 kb MAX

役に立ちましたか?

解決

it depends on what's inside your table. If you have 1000 rows with 1mb of data, you will have 1000 Mb

Try running:

select datalength(yourField) from yourTable

the datalength function will give you how many bytes are occupied by the column

他のヒント

varchar(max) is different with varchr(n);

a varchar(max) cell can contain 2 GByte data.

but for varchar(n): the max number of n is 8000, means max 8 KByte data.

but, any way, I don't know what kind of data you stored in your database.

so,in short, possibly normal.

Run sys.sp_spaceused @objname = N'YourTable'; to see the space used by your table.

If there is no unused space, then your data is really taking up that space

If there is a lot of unused space, you could try creating a new filegroup and moving the text/varchar(max) columns to this new file group, and shrinking the database DBCC SHRINKDB

After that your primary filegroup will take up less space, and you can shrink the "offending" file using DBCC SHRINKFILE, whenever problem arises.

Creating a new filegroup can be done from SSMS, in the database properties, files page. You can generate the sql script from there to see what's going on.

Moving text columns to a different filegroup can be made by using the TEXTIMAGE_ON { filegroup| "default" } in CREATE TABLE

Sorry: no alter table possible, no individual column to different filegroup, but all "big" columns at once. So you have to do it by hand or show your table in a new database diagram (in SSMS studio) and change the property ... sorry I don't know it's name, something like "Text/Image filegroup" (I suppose, I've got Spanish SSMS), but it's there when you see the table properties in the database diagram designer.

Advantages: less fragmentation on the main table, faster table/clustered index sacans and possiblity to shrink only the file you're interested in: the with the problematic "big" columns.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top