I have a database that is used for development and testing purpose on a web server. What I would like to do is add one column to the table that contains approximately 50,000 records (please note that I am not a database administrator). I am connecting through SSMS with credentials provided by our provider and executing next query
ALTER TABLE MyTable
ADD MyCol BIT
CONSTRAINT MyConstraint DEFAULT 1 NOT NULL
The error I get is:
Msg 9002, Level 17, State 4, Line 2
The transaction log for database 'my_db' is full. To find out why space in the log cannot be reused, see the log_reuse_wait_desc column in sys.databases
If I execute
SELECT log_reuse_wait_desc, *
FROM sys.databases WHERE name ='my_db'
GO
in a batch together with Add MyCol, log_reuse_wait_desc will be ACTIVE_TRANSACTION. If I execute it as a separate command, it will be CHECKPOINT
Recovery mode for database is set to simple. I have searched for a solution on internet, and people are either suggesting to set recovery mode to simple (which already is), or to backup a log file and then shrink it, which some experts consider very bad practice.
So what I need to do to add simple NOT NULL column to a table with data?
Edit: Here is the solution, if someone doesn't want to read through all answers:
to get the size of the Transaction log, this is how I did it:
sp_helpdb 'YouDatabaseName'
In result window you will get the size of the log file (mine was 8MB). To increase it to larger value, use this query:
ALTER DATABASE YourDatabaseName
MODIFY FILE(NAME = YourDatabaseLogName, SIZE=128MB);
GO
And the error will be gone.