'Incorrect SET Options' Error When Building Database Project

后端 未结 6 1508
长情又很酷
长情又很酷 2020-12-03 01:02

We are using Visual Studio and a database project to generate our database.

I just made a number of database changes (including adding a new table named Corres

6条回答
  •  执念已碎
    2020-12-03 01:24

    In my case I was trying to create a table from one database to another on MS SQL Server 2012. Right-clicking on a table and selecting Script Table as > DROP And CREATE To > New Query Editor Window, following script was created:

    USE [SAMPLECOMPANY]
    GO
    
    ALTER TABLE [dbo].[Employees] DROP CONSTRAINT [FK_Employees_Departments]
    GO
    
    /****** Object:  Table [dbo].[Employees]    Script Date: 8/24/2016 9:31:15 PM ******/
    DROP TABLE [dbo].[Employees]
    GO
    
    /****** Object:  Table [dbo].[Employees]    Script Date: 8/24/2016 9:31:15 PM ******/
    SET ANSI_NULLS ON
    GO
    
    SET QUOTED_IDENTIFIER ON
    GO
    
    SET ANSI_PADDING ON
    GO
    
    CREATE TABLE [dbo].[Employees](
        [EmployeeId] [int] IDENTITY(1,1) NOT NULL,
        [DepartmentId] [int] NOT NULL,
        [FullName] [varchar](50) NOT NULL,
        [HireDate] [datetime] NULL
     CONSTRAINT [PK_Employees] PRIMARY KEY CLUSTERED 
    (
        [EmployeeId] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    
    GO
    
    SET ANSI_PADDING OFF
    GO
    
    ALTER TABLE [dbo].[Employees]  WITH CHECK ADD  CONSTRAINT [FK_Employees_Departments] FOREIGN KEY([DepartmentId])
    REFERENCES [dbo].[Departments] ([DepartmentID])
    GO
    
    ALTER TABLE [dbo].[Employees] CHECK CONSTRAINT [FK_Employees_Departments]
    GO
    

    However when executing above script it was returning the error:

    SELECT failed because the following SET options have incorrect settings: 'ANSI_PADDING'. Verify that SET options are correct for use with indexed views and/or indexes on computed columns and/or filtered indexes and/or query notifications and/or XML data type methods and/or spatial index operations.

    The Solution I've found: Enabling the settings on the Top of the script like this:

    USE [SAMPLECOMPANY]
    GO
    /****** Object:  Table [dbo].[Employees]    Script Date: 8/24/2016 9:31:15 PM ******/
    SET ANSI_NULLS ON
    GO
    
    SET QUOTED_IDENTIFIER ON
    GO
    
    SET ANSI_PADDING ON
    GO
    
    ALTER TABLE [dbo].[Employees] DROP CONSTRAINT [FK_Employees_Departments]
    GO
    
    /****** Object:  Table [dbo].[Employees]    Script Date: 8/24/2016 9:31:15 PM ******/
    DROP TABLE [dbo].[Employees]
    GO
    
    
    
    CREATE TABLE [dbo].[Employees](
        [EmployeeId] [int] IDENTITY(1,1) NOT NULL,
        [DepartmentId] [int] NOT NULL,
        [FullName] [varchar](50) NOT NULL,
        [HireDate] [datetime] NULL
     CONSTRAINT [PK_Employees] PRIMARY KEY CLUSTERED 
    (
        [EmployeeId] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    
    GO
    
    ALTER TABLE [dbo].[Employees]  WITH CHECK ADD  CONSTRAINT [FK_Employees_Departments] FOREIGN KEY([DepartmentId])
    REFERENCES [dbo].[Departments] ([DepartmentID])
    GO
    
    ALTER TABLE [dbo].[Employees] CHECK CONSTRAINT [FK_Employees_Departments]
    GO
    
    SET ANSI_PADDING OFF
    GO
    

    Hope this help.

提交回复
热议问题