Could not allocate space for object dbo.table - sql-server

The number of rows in the table is only 601 records. Looking in the database I cannot see any problems: the initial size is set to 4Gb, autogrowth is set by 1Mb (I then set it to 10%) but this did not make any difference.
Could not allocate space for object 'dbo.Fatawa'.'PK_table' in database 'database' because
the 'PRIMARY' filegroup is full. Create disk space by deleting unneeded files, dropping objects in the filegroup, adding additional files to the filegroup, or setting autogrowth on for existing files in the filegroup.

The error message is telling you that the PRIMARY filegroup (FG) is full. In SQL Server Management Studio (SSMS), right click the database and selection properties.
On the files table, find the primary data file (*.mdf) and write down the location (drive, path, file).
Go to Windows explorer, click the my computer icon, notice the drives. Each drive will have total space and amount available.
Problem:
Is there any space left on the drive? If not, that is your problem.
Solution:
If there is space left in the data file, shrink the file. If not, create a secondary data file. Move some tables to the data file. Shrink the primary data file after move is complete.
Here is a script from microsoft by Roberto Stefanetti. It will move a table and indexes from one FG to another.
http://gallery.technet.microsoft.com/scriptcenter/c1da9334-2885-468c-a374-775da60f256f

i used the stored procedure:
sp_helpdb (DB name)
this showed me the growth size was too small so i changed it like this:
ALTER DATABASE (DB name)
MODIFY FILE
(NAME=(DB name),FILEGROWTH=20MB);

In my case I use SQL Server 2005 EXPRESS version and this have database limitation to 4 GB max size.
I get this error:
Could not allocate space for object 'dbo.SORT temporary run
storage:440737612283904' in database 'LargeDB' because the 'PRIMARY'
filegroup is full Create disk space by deleting unneeded
files,dropping objects in the filegroup, adding additional files to
the filegroup, or setting autogrowth on for existing files in the
filegroup...
To solve this problem you need to upgrade to SQL Server version 2008 R2 Express Database Size Limit Increased to 10GB, or upgrade your license.

Related

MSSQL - 2TB Database - New file in Primary Group

I have yet to find a good answer to this online.
The issue:
I have a 2TB database with only one table (archive). Unfortunately, the hard drive will soon be full and I need to somehow split data.
An extension of the hard disk is not possible in the short term. But there is another hard disk where I could store data on it. This one is 1TB in size.
The database has only one primary filegroup and one file to it.
If I add a new file to the filegroup, can I put this file on the 1TB and the database then writes its data there?
If I add a new file to the filegroup, can I put this file on the 1TB and the database then writes its data there?
Yes. SQL Server uses a "proportional fill algorithm" when a filegroup has multiple files.
Filegroups use a proportional fill strategy across all the files
within each filegroup. As data is written to the filegroup, the SQL
Server Database Engine writes an amount proportional to the free space
in the file to each file within the filegroup, instead of writing all
the data to the first file until full. It then writes to the next
file. For example, if file f1 has 100 MB free and file f2 has 200 MB
free, one extent is given from file f1, two extents from file f2, and
so on. In this way, both files become full at about the same time, and
simple striping is achieved.
File and Filegroup Fill Strategy
So if you add a new file, all (or almost all) of the new allocations will be from that file. And so you can easily add usable space by adding a new file to your primary filegroup.
Add a new file to your primary filegroup, data will be distributed in another disk as per your requirement. Even you can add more log files as well.
in your case, if the log file size is high then you can move your log file(.ldf) to another disk.

Could not allocate space for object in database because the 'PRIMARY' filegroup is full

Could not allocate space for object in database because the 'PRIMARY' filegroup is full.
Create disk space by deleting unneeded files, dropping objects in the filegroup, adding additional files to the filegroup, or setting autogrowth on for existing files in the filegroup.
I am getting this error even when I have enough Hard Disk Space. Please advice. I have checked related topics but not helpful.
You should configure Maximum File Size and AutoGrowth of primary files. You can find the settings with following instructions;
Move to YourDatabase -> Properties -> Files and find the files which are inside the primary filegroup and configure the Maximum File Size and AutoGrowth settings.

Shrink the database in SQL Server

I have a database which is almost full and we have some options to deal with this:
we can increase the db file size
shrink the database
Before I choose the first option, I want to know how can I check the database size and how much data is really in there so that I may can shrink the database to get some free space.
So see where you have unused space , what file is how big use the following query....
Use DatabaseName
GO
Select name AS [FileName]
, size/128.0 AS [FileSize(MB)]
, fileproperty(name, 'SpaceUsed')/128.0 AS [Space_Used(MB)]
, (size - fileproperty(name, 'SpaceUsed')) /128.0 AS [FreeSpace(MB)]
From dbo.sysfiles
GO
Finally when you have decided to shrink a file with lots of free space you can use DBCC shrinkfile command to do so.
USE DatabaseName
GO
DBCC SHRINKFILE ('FileName', 10) --<-- will shrink it to 10 MB
GO
Note
If any of the unused space was occupied by the BLOB data type(text, ntext, xml etc) column, you may not be able to claim back that unused space unless you drop and recreate the table again.
You can get this information a couple of different ways. In SSMS you can right click on the database, choose properties and look at files. You data and log files will display an "Initial" value indicating size.
You can right click the DB, click on Tasks and Shrink, then Files and the data file should be the default displayed. This will show you your size and free space.
You can also run a script showing you all the size and location info for your databases. There are several out there you can find with a quick Google Search.
Additionally, there are some built in SPs that can get you that info as described here The fourth query in particular shows you the amount of free space.

How to set initial database file size and filegrowth in a database project?

I'm trying to set the initial database file size and its auto growth parameter in a Database Project in Visual Studio to be used with the Publish option. I've added a Filegroup file (SqlFile1.sql) to the project with the following contents:
ALTER DATABASE [$(DatabaseName)]
ADD FILE
(
NAME = [SqlFile1],
FILENAME = '$(DefaultDataPath)$(DefaultFilePrefix)_SqlFile1.ndf',
SIZE = 5000MB,
MAXSIZE = UNLIMITED,
FILEGROWTH = 50%
) TO FILEGROUP [PRIMARY]
(documentation).
When I click Publish with the option Always re-create database checked, the file SqlFile1 is created within the PRIMARY filegroup, but has the Initial size set to 3 MB and Autogrowth is By 1 MB, unrestricted growth. There are no error or warning messages.
What's interesting, the following SQL script:
ALTER DATABASE DatabaseTest
MODIFY FILE (NAME = [SqlFile1], SIZE = 5000MB, FILEGROWTH = 50%);
GO
ran from SQL Management Studio correctly modifies file's properties.
Why are my settings ignored and how to make them work?
The scripts created in the bin directory suggest that properties other than logical file name, physical file name and target file group are indeed ignored. Eventually I solved this issue by adding a post-deployment script. To do this right click the database project and choose Add -> New item -> User scripts -> Post-Deployment Script. In this script you can modify the database anyway you want, in this case alter file's properties with:
ALTER DATABASE [$(DatabaseName)]
MODIFY FILE
(
NAME = [SqlFile1],
SIZE = 5000MB,
MAXSIZE = UNLIMITED,
FILEGROWTH = 50%
)
The correct size and filegrowth settings can be set by creating a Filegroup file object the way you've been trying, but the key is that you also need to set an advanced publish setting of Script file size to true.
Now there's another gotcha to this, in that if you publish/create the database first without this option checked, then subsequent publish operations will not correctly apply the file size settings even if you've since checked this option. This is likely because the object has already been created, though I don't see why the dacfx libraries couldn't perform a similar diff to the way they do on tables. At this point you'd need to either manually change the file settings or add a post deployment script as you've mentioned here.
For reference here is a comparison to show the difference in initial create database operations with and without the Script file size option.
Without Script file size
With Script file size
With the option checked you can see the correct file size options are applied to the database deployment without the requirement of a post deployment modify db script
According to this post of a user who had the same issue, these setting are apparently missing in database projects:
only some database properties are available in VS database projects. In particular size and autogrowth settings are missing.
This blog however does suggest you can work around it by editing values in the .sql files directly (not via the IDE):
You can change filegrowth (and other) settings of the database project, however these aren't available through the VS 2010 IDE. Instead you have to edit .sql files found here:
[Project location][Database project name]\Schema
Objects\Storage\Files

Should image binaries be stored as BLOBS in a SQL Server?

If an application requires images (ie. JPGs, PNGs etc) to be referenced in a database-driven application, should these images just be stored in a file system with their path referenced in a database, or should the images actually be stored in the database as BLOBS?
There's a really good paper by Microsoft Research called To Blob or Not To Blob.
Their conclusion after a large number of performance tests and analysis is this:
if your pictures or document are typically below 256K in size, storing them in a database VARBINARY column is more efficient
if your pictures or document are typically over 1 MB in size, storing them in the filesystem is more efficient (and with SQL Server 2008's FILESTREAM attribute, they're still under transactional control and part of the database)
in between those two, it's a bit of a toss-up depending on your use
If you decide to put your pictures into a SQL Server table, I would strongly recommend using a separate table for storing those pictures - do not store the employee foto in the employee table - keep them in a separate table. That way, the Employee table can stay lean and mean and very efficient, assuming you don't always need to select the employee foto, too, as part of your queries.
For filegroups, check out Files and Filegroup Architecture for an intro. Basically, you would either create your database with a separate filegroup for large data structures right from the beginning, or add an additional filegroup later. Let's call it "LARGE_DATA".
Now, whenever you have a new table to create which needs to store VARCHAR(MAX) or VARBINARY(MAX) columns, you can specify this file group for the large data:
CREATE TABLE dbo.YourTable
(....... define the fields here ......)
ON Data -- the basic "Data" filegroup for the regular data
TEXTIMAGE_ON LARGE_DATA -- the filegroup for large chunks of data
Check out the MSDN intro on filegroups, and play around with it!

Resources