Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2010

    Unanswered: Incorrect syntax near '('

        IDENTITY(int, 1, 1) AS FragIndexId, 
        [object_id] AS ObjectId, 
        index_id AS IndexId, 
        avg_fragmentation_in_percent AS FragPercent, 
        record_count AS RecordCount, 
        partition_number AS PartitionNumber,
    	index_type_desc AS IndexType,
    	alloc_unit_type_desc AS AllocUnitType
    INTO #FragIndex
    FROM sys.dm_db_index_physical_stats (DB_ID(@dbName), NULL, NULL, NULL, @statsMode)
        avg_fragmentation_in_percent > @minFragPercent AND 
        avg_fragmentation_in_percent < @maxFragPercent AND 
        index_id > 0
    ORDER BY ObjectId
    This query which is found on Tara Kizer's blog, for defragmenting and updating indexes in a database, I get the error "Incorrect syntax near '(' and it points me to the line in marked in color above...


    Heres the link to a zipfile, which contains the stored procedure I am trying to "install":

    Why all this? Well, my database is running quite slow after a Complete Restore of it, so I want to update all stats and rebuild all indexes on it.

    PS: Using sql server 2008 R2.

    Edit: Quite strange, I craeted a new Empty database and right clicked the database "new query", and pasted the whole procedure inside it, then created the procedure successfully. Why???
    So I changed the beginning of the whole procedure from "Use db<companyname>;" to "Use Test;" at the very top, and it created it...

    Guess it is solved then, but strange that I couldnt create the stored procedure within the database I wanted, ...oh well..
    Last edited by ManyTimes; 10-26-12 at 06:32.

  2. #2
    Join Date
    Jan 2003
    Provided Answers: 17
    Is the database you wanted to run this in set to a lower compatibility setting (SQL 2000 mode)?

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts