Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7753859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:09:34+00:00 2026-06-01T12:09:34+00:00

In our database there is a table which is created with ANSI_NULLS OFF .

  • 0

In our database there is a table which is created with ANSI_NULLS OFF. Now we have created a view using this table. And we want to add a clustered index for this view.

While creating the clustered index it is showing an error like can’t create an index since the ANSI_NULL is off for this particular table.

This table contains a large amount of data. So I want to change this option to ON without losing any data.

Is there any way to alter the table to modify this option . Please give your suggestions.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T12:09:36+00:00Added an answer on June 1, 2026 at 12:09 pm

    This was cross posted on Database Administrators so I might as well post my answer from there here too to help future searchers.

    It can be done as a metadata only change (i.e. without migrating all the data to a new table) using ALTER TABLE ... SWITCH.

    Example code below

    /*Create table with option off*/ 
    SET ANSI_NULLS OFF; 
    
    CREATE TABLE dbo.YourTable (X INT) 
    
    /*Add some data*/ 
    INSERT INTO dbo.YourTable VALUES (1),(2),(3) 
    
    /*Confirm the bit is set to 0*/ 
    SELECT uses_ansi_nulls, * 
    FROM   sys.tables 
    WHERE  object_id = object_id('dbo.YourTable') 
    
    GO 
    
    BEGIN TRY 
        BEGIN TRANSACTION; 
        /*Create new table with identical structure but option on*/
        SET ANSI_NULLS ON; 
        CREATE TABLE dbo.YourTableNew (X INT) 
    
        /*Metadata only switch*/
        ALTER TABLE dbo.YourTable  SWITCH TO dbo.YourTableNew;
    
        DROP TABLE dbo.YourTable; 
    
        EXECUTE sp_rename N'dbo.YourTableNew', N'YourTable','OBJECT'; 
    
        /*Confirm the bit is set to 1*/ 
        SELECT uses_ansi_nulls, * 
        FROM   sys.tables 
        WHERE  object_id = object_id('dbo.YourTable') 
    
        /*Data still there!*/ 
        SELECT * 
        FROM dbo.YourTable
    
        COMMIT TRANSACTION; 
    END TRY 
    
    BEGIN CATCH 
        IF XACT_STATE() <> 0 
          ROLLBACK TRANSACTION; 
    
        PRINT ERROR_MESSAGE(); 
    END CATCH; 
    

    WARNING: when your table contains an IDENTITY column you need to reseed the IDENTITY value.
    The SWITCH TO will reset the seed of the identity column and if you do not have a UNIQUE or PRIMARY KEY constraint on the identity (e.g. when using CLUSTERED COLUMNSTORE index in SQL 2014) you won’t notice it right away.
    You need to use DBCC CHECKIDENT (‘dbo.YourTable’, RESEED, [reseed value]) to correctly set the seed value again.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a query that is currently killing our database and I know there
On our live/production database I'm trying to add a trigger to a table, but
I have a database which has a table with an XML column. The XML
We are getting this error on a table in our database: Cannot create a
We need to perform the following operation in our database : There is a
There are two variables in our database called OB and B2B_OB . There are
There is a constant change (!) in our database, new columns are often added.
Currently I am designing a database for use in our company. We are using
i am creating an app that needs a database. i created it using sqlite
We have around 100 database migration files. Many of them make schema changes which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.