We are using SQL Server 2008. We have an Existing database and it was required to ADD a new COLUMN to one of the Table which has 2700 rows only but one of its column is of type VARCHAR(8000). When i try to add new column (CHAR(1) NULL) by using ALTER table command, it takes too much time!! it took 5 minutes and the command was still running to i stopped the command.
Below is the command, i was trying to add new column:
ALTER TABLE myTable Add ColumnName CHAR(1) NULL
- Can someone help me to understand that How the SQL Server handles
the ALTER Table command? what happens exactly? - Why it takes so much time to Add new column
EDIT:
- What is the effect of Table size on ALTER Command?
Altering a table requires a schema lock. Many other operations require the same lock too. After all, it wouldn’t make sense to add a column halfway a
selectstatement.So a likely explanation is that a process had the table locked for 5 minutes. The
ALTERthen has to wait until it gets the lock itself.You can see blocked processes, and the blocking process, from the Activity Monitor in SQL Server Management Studio.