Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««12

Index optimization failed for User databases Expand / Collapse
Author
Message
Posted Wednesday, January 2, 2013 4:27 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Tuesday, November 4, 2014 8:46 PM
Points: 1,786, Visits: 1,015
copy paste the content of @command into SSMS and then do a syntax check

Jayanth Kurup
Post #1401764
Posted Tuesday, January 15, 2013 8:16 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Thursday, December 18, 2014 7:01 AM
Points: 208, Visits: 776
anthony.green (1/2/2013)
Check sys.indexes in every database where the name has -

IF @frag < 30.0
SET @command = N''ALTER INDEX ['' + @indexname + N''] ON ['' +@DBname+ N''].[''+ @schemaname + N''].['' + @objectname + N''] REORGANIZE'';
IF @frag >= 30.0
SET @command = N''ALTER INDEX ['' + @indexname + N''] ON ['' +@DBname+ N''].['' + @schemaname + N''].['' + @objectname + N''] REBUILD'';
IF @partitioncount > 1
SET @command = @command + N'' PARTITION='' + CAST(@partitionnum AS nvarchar(10));
EXEC (@command);
-- PRINT N''Executed: '' + @command;
END;

Added extra [] around the db schema object in case anything else has special characters in the name.


Hi Anthony,
Thanks for the update........

The above script is worked for me and job ran successfully in one server . I did same changes in another server (index optimization job),but the job was failing with the below error after changes also....

Mensaje
Executed as user: NT AUTHORITY\SYSTEM. Incorrect syntax near'('. [SQLSTATE 42000] (Error 102). The step failed.


Thanks
Lavanya

Post #1407286
Posted Tuesday, January 15, 2013 8:19 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Yesterday @ 1:14 PM
Points: 40,615, Visits: 37,081
Print the command (rather than executing it) and see what it returns.


Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #1407290
Posted Tuesday, January 15, 2013 8:24 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Thursday, December 18, 2014 7:01 AM
Points: 208, Visits: 776
Sorry Gila,

i am not getting you .. can you please explain more ...

I need to execute the script manually or ???
Post #1407292
Posted Tuesday, January 15, 2013 8:44 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Monday, December 8, 2014 1:45 AM
Points: 5,221, Visits: 5,120
Instead of exec (@command), do print @command, then you can see where the failing object is.



Want an answer fast? Try here
How to post data/code for the best help - Jeff Moden
Need a string splitter, try this - Jeff Moden
How to post performance problems - Gail Shaw
CrossTabs-Part1 & Part2 - Jeff Moden
SQL Server Backup, Integrity Check, and Index and Statistics Maintenance - Ola Hallengren
Managing Transaction Logs - Gail Shaw
Troubleshooting SQL Server: A Guide for the Accidental DBA - Jonathan Kehayias and Ted Krueger

Post #1407305
Posted Tuesday, January 15, 2013 8:57 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Thursday, December 18, 2014 7:01 AM
Points: 208, Visits: 776
so i need to change the script as follow


EXEC (@command); replace with Print(@command); right??

but the server language is spanish ??

Post #1407314
Posted Tuesday, January 15, 2013 9:01 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Monday, December 8, 2014 1:45 AM
Points: 5,221, Visits: 5,120
But the command you are executing is ALTER INDEX,

So it will print out ALTER INDEX indexname ON tablename .....

So you can debug what you have told SQL to build and execute, so you will need to find all occurances of - in the output and you know where your problem then lies.




Want an answer fast? Try here
How to post data/code for the best help - Jeff Moden
Need a string splitter, try this - Jeff Moden
How to post performance problems - Gail Shaw
CrossTabs-Part1 & Part2 - Jeff Moden
SQL Server Backup, Integrity Check, and Index and Statistics Maintenance - Ola Hallengren
Managing Transaction Logs - Gail Shaw
Troubleshooting SQL Server: A Guide for the Accidental DBA - Jonathan Kehayias and Ted Krueger

Post #1407319
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse