Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Old Forums
 CLOSED - General SQL Server
 DBCC DBREINDEX

Author  Topic 

tinybunny_8
Starting Member

6 Posts

Posted - 2005-06-09 : 10:55:47
Hi all,

I am trying to rebuild all indexes in a table using the following statements :

SELECT @execstr = 'DBCC DBREINDEX (' + RTRIM(@objectid) + ','',100)'
EXEC (@execstr)

I encountered the following error messages:

Server: Msg 105, Level 15, State 1, Line 1
Unclosed quotation mark before the character string ',100)'.
Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near ',100)'.

I tried the following statements:

SELECT @execstr = 'DBCC DBREINDEX (' + RTRIM(@objectid) + ',100)'
EXEC (@execstr)

then I received the following messages:

Server: Msg 2560, Level 16, State 14, Line 1
Parameter 2 is incorrect for this DBCC statement.
Server: Msg 2560, Level 16, State 1, Line 1
Parameter 1 is incorrect for this DBCC statement.

I have checked the other statements in the procedure, and they are just fine but the above statements.
Does anyone have suggestion what might go wrong with the above statements?
Thanks in advanced.

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2005-06-09 : 11:25:19
Didn't you even look at the value that you got in @execstr? I think if you add a print statement, you will see something like this:
DBCC DBREINDEX (3249872,',100)

You have an unclosed quote, the same as the error message says.


CODO ERGO SUM
Go to Top of Page

tinybunny_8
Starting Member

6 Posts

Posted - 2005-06-09 : 16:03:08
Michael,
Thanks for your reply. You were right, and also, dbreindex can use only table name/object name not the object id.
The correct one should be:

SELECT @execstr = 'DBCC DBREINDEX (' + RTRIM(@tablename)+ ','''',100)'
EXEC (@execstr)
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2005-06-09 : 16:05:27
http://weblogs.sqlteam.com/tarad/archive/2005/01/04/3933.aspx

Tara
Go to Top of Page
   

- Advertisement -