none
Database not getting created on executing .sql file RRS feed

  • Question

  • Hi all. I have made some changes to a database model using model-first. After VS 2013 generates the sql file (which i expect to right click on and execute to get changes updated to my database), when i try to execute the file, i get errors such as:

    Msg 3726, Level 16, State 1, Line 50
    Could not drop object 'dbo.Users' because it is referenced by a FOREIGN KEY constraint.
    Msg 3726, Level 16, State 1, Line 53
    Could not drop object 'dbo.Answers' because it is referenced by a FOREIGN KEY constraint.
    Msg 3726, Level 16, State 1, Line 56
    Could not drop object 'dbo.Questions' because it is referenced by a FOREIGN KEY constraint.
    Msg 2714, Level 16, State 6, Line 93
    There is already an object named 'Users' in the database.
    Msg 2714, Level 16, State 6, Line 101
    There is already an object named 'Answers' in the database.
    Msg 2714, Level 16, State 6, Line 109
    There is already an object named 'Questions' in the database.
    Msg 1779, Level 16, State 0, Line 153
    Table 'Users' already has a primary key defined on it.
    Msg 1750, Level 16, State 0, Line 153
    Could not create constraint. See previous errors.
    Msg 1779, Level 16, State 0, Line 159
    Table 'Answers' already has a primary key defined on it.
    Msg 1750, Level 16, State 0, Line 159
    Could not create constraint. See previous errors.
    Msg 1779, Level 16, State 0, Line 165
    Table 'Questions' already has a primary key defined on it.
    Msg 1750, Level 16, State 0, Line 165
    Could not create constraint. See previous errors.
    Msg 1769, Level 16, State 1, Line 215
    Foreign key 'FK_SectionQuestion' references invalid column 'SectionSectionId' in referencing table 'Questions'.
    Msg 1750, Level 16, State 0, Line 215
    Could not create constraint. See previous errors.

    Below is my generated .sql file:

    -- --------------------------------------------------
    -- Entity Designer DDL Script for SQL Server 2005, 2008, 2012 and Azure
    -- --------------------------------------------------
    -- Date Created: 08/06/2014 15:59:58
    -- Generated from EDMX file: E:\My Documents\Visual Studio 2013\Projects\ExamGenerator\ExamGenerator\ExamDatabase.edmx
    -- --------------------------------------------------
    
    SET QUOTED_IDENTIFIER OFF;
    GO
    USE [master];
    GO
    IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
    GO
    
    -- --------------------------------------------------
    -- Dropping existing FOREIGN KEY constraints
    -- --------------------------------------------------
    
    IF OBJECT_ID(N'[dbo].[FK_ExamSection]', 'F') IS NOT NULL
        ALTER TABLE [dbo].[Sections] DROP CONSTRAINT [FK_ExamSection];
    GO
    IF OBJECT_ID(N'[dbo].[FK_UserExam]', 'F') IS NOT NULL
        ALTER TABLE [dbo].[Exams] DROP CONSTRAINT [FK_UserExam];
    GO
    IF OBJECT_ID(N'[dbo].[FK_SectionQuestion]', 'F') IS NOT NULL
        ALTER TABLE [dbo].[Questions] DROP CONSTRAINT [FK_SectionQuestion];
    GO
    IF OBJECT_ID(N'[dbo].[FK_QuestionAnswer]', 'F') IS NOT NULL
        ALTER TABLE [dbo].[Answers] DROP CONSTRAINT [FK_QuestionAnswer];
    GO
    IF OBJECT_ID(N'[dbo].[FK_QuestionSubQuestion]', 'F') IS NOT NULL
        ALTER TABLE [dbo].[SubQuestions] DROP CONSTRAINT [FK_QuestionSubQuestion];
    GO
    IF OBJECT_ID(N'[dbo].[FK_SubQuestionSubQuestionsAnswer]', 'F') IS NOT NULL
        ALTER TABLE [dbo].[SubQuestionsAnswers] DROP CONSTRAINT [FK_SubQuestionSubQuestionsAnswer];
    GO
    
    -- --------------------------------------------------
    -- Dropping existing tables
    -- --------------------------------------------------
    
    IF OBJECT_ID(N'[dbo].[Exams]', 'U') IS NOT NULL
        DROP TABLE [dbo].[Exams];
    GO
    IF OBJECT_ID(N'[dbo].[Sections]', 'U') IS NOT NULL
        DROP TABLE [dbo].[Sections];
    GO
    IF OBJECT_ID(N'[dbo].[Users]', 'U') IS NOT NULL
        DROP TABLE [dbo].[Users];
    GO
    IF OBJECT_ID(N'[dbo].[Answers]', 'U') IS NOT NULL
        DROP TABLE [dbo].[Answers];
    GO
    IF OBJECT_ID(N'[dbo].[Questions]', 'U') IS NOT NULL
        DROP TABLE [dbo].[Questions];
    GO
    IF OBJECT_ID(N'[dbo].[SubQuestions]', 'U') IS NOT NULL
        DROP TABLE [dbo].[SubQuestions];
    GO
    IF OBJECT_ID(N'[dbo].[SubQuestionsAnswers]', 'U') IS NOT NULL
        DROP TABLE [dbo].[SubQuestionsAnswers];
    GO
    
    -- --------------------------------------------------
    -- Creating all tables
    -- --------------------------------------------------
    
    -- Creating table 'Exams'
    CREATE TABLE [dbo].[Exams] (
        [ExamID] int IDENTITY(1,1) NOT NULL,
        [UnitCode] nvarchar(max)  NOT NULL,
        [UnitName] nvarchar(max)  NOT NULL,
        [ExamDate] nvarchar(max)  NULL,
        [Duration] float  NOT NULL,
        [Instructions] nvarchar(max)  NOT NULL,
        [University] nvarchar(max)  NOT NULL,
        [Course] nvarchar(max)  NOT NULL,
        [UserUserId] int  NOT NULL
    );
    GO
    
    -- Creating table 'Sections'
    CREATE TABLE [dbo].[Sections] (
        [SectionId] int IDENTITY(1,1) NOT NULL,
        [SectionName] nvarchar(max)  NOT NULL,
        [Marks] int  NOT NULL,
        [ExamExamID] int  NOT NULL
    );
    GO
    
    -- Creating table 'Users'
    CREATE TABLE [dbo].[Users] (
        [UserId] int IDENTITY(1,1) NOT NULL,
        [UserName] nvarchar(max)  NOT NULL,
        [Password] nvarchar(max)  NOT NULL
    );
    GO
    
    -- Creating table 'Answers'
    CREATE TABLE [dbo].[Answers] (
        [AnswerId] int  NOT NULL,
        [AnswerPhrase] nvarchar(max)  NULL,
        [Diagram] varbinary(max)  NULL
    );
    GO
    
    -- Creating table 'Questions'
    CREATE TABLE [dbo].[Questions] (
        [QuestionId] int IDENTITY(1,1) NOT NULL,
        [QuestionPhrase] nvarchar(max)  NOT NULL,
        [Diagram] varbinary(max)  NULL,
        [Marks] decimal(18,1)  NOT NULL,
        [SectionSectionId] int  NOT NULL
    );
    GO
    
    -- Creating table 'SubQuestions'
    CREATE TABLE [dbo].[SubQuestions] (
        [SubQuestionId] int IDENTITY(1,1) NOT NULL,
        [SubQuestionPhrase] nvarchar(max)  NULL,
        [Diagram] varbinary(max)  NULL,
        [Marks] decimal(18,0)  NULL,
        [QuestionQuestionId] int  NOT NULL
    );
    GO
    
    -- Creating table 'SubQuestionsAnswers'
    CREATE TABLE [dbo].[SubQuestionsAnswers] (
        [SubQuestionAnswerId] int  NOT NULL,
        [AnswerPhrase] nvarchar(max)  NULL,
        [Diagram] varbinary(max)  NULL
    );
    GO
    
    -- --------------------------------------------------
    -- Creating all PRIMARY KEY constraints
    -- --------------------------------------------------
    
    -- Creating primary key on [ExamID] in table 'Exams'
    ALTER TABLE [dbo].[Exams]
    ADD CONSTRAINT [PK_Exams]
        PRIMARY KEY CLUSTERED ([ExamID] ASC);
    GO
    
    -- Creating primary key on [SectionId] in table 'Sections'
    ALTER TABLE [dbo].[Sections]
    ADD CONSTRAINT [PK_Sections]
        PRIMARY KEY CLUSTERED ([SectionId] ASC);
    GO
    
    -- Creating primary key on [UserId] in table 'Users'
    ALTER TABLE [dbo].[Users]
    ADD CONSTRAINT [PK_Users]
        PRIMARY KEY CLUSTERED ([UserId] ASC);
    GO
    
    -- Creating primary key on [AnswerId] in table 'Answers'
    ALTER TABLE [dbo].[Answers]
    ADD CONSTRAINT [PK_Answers]
        PRIMARY KEY CLUSTERED ([AnswerId] ASC);
    GO
    
    -- Creating primary key on [QuestionId] in table 'Questions'
    ALTER TABLE [dbo].[Questions]
    ADD CONSTRAINT [PK_Questions]
        PRIMARY KEY CLUSTERED ([QuestionId] ASC);
    GO
    
    -- Creating primary key on [SubQuestionId] in table 'SubQuestions'
    ALTER TABLE [dbo].[SubQuestions]
    ADD CONSTRAINT [PK_SubQuestions]
        PRIMARY KEY CLUSTERED ([SubQuestionId] ASC);
    GO
    
    -- Creating primary key on [SubQuestionAnswerId] in table 'SubQuestionsAnswers'
    ALTER TABLE [dbo].[SubQuestionsAnswers]
    ADD CONSTRAINT [PK_SubQuestionsAnswers]
        PRIMARY KEY CLUSTERED ([SubQuestionAnswerId] ASC);
    GO
    
    -- --------------------------------------------------
    -- Creating all FOREIGN KEY constraints
    -- --------------------------------------------------
    
    -- Creating foreign key on [ExamExamID] in table 'Sections'
    ALTER TABLE [dbo].[Sections]
    ADD CONSTRAINT [FK_ExamSection]
        FOREIGN KEY ([ExamExamID])
        REFERENCES [dbo].[Exams]
            ([ExamID])
        ON DELETE NO ACTION ON UPDATE NO ACTION;
    
    -- Creating non-clustered index for FOREIGN KEY 'FK_ExamSection'
    CREATE INDEX [IX_FK_ExamSection]
    ON [dbo].[Sections]
        ([ExamExamID]);
    GO
    
    -- Creating foreign key on [UserUserId] in table 'Exams'
    ALTER TABLE [dbo].[Exams]
    ADD CONSTRAINT [FK_UserExam]
        FOREIGN KEY ([UserUserId])
        REFERENCES [dbo].[Users]
            ([UserId])
        ON DELETE NO ACTION ON UPDATE NO ACTION;
    
    -- Creating non-clustered index for FOREIGN KEY 'FK_UserExam'
    CREATE INDEX [IX_FK_UserExam]
    ON [dbo].[Exams]
        ([UserUserId]);
    GO
    
    -- Creating foreign key on [SectionSectionId] in table 'Questions'
    ALTER TABLE [dbo].[Questions]
    ADD CONSTRAINT [FK_SectionQuestion]
        FOREIGN KEY ([SectionSectionId])
        REFERENCES [dbo].[Sections]
            ([SectionId])
        ON DELETE NO ACTION ON UPDATE NO ACTION;
    
    -- Creating non-clustered index for FOREIGN KEY 'FK_SectionQuestion'
    CREATE INDEX [IX_FK_SectionQuestion]
    ON [dbo].[Questions]
        ([SectionSectionId]);
    GO
    
    -- Creating foreign key on [AnswerId] in table 'Answers'
    ALTER TABLE [dbo].[Answers]
    ADD CONSTRAINT [FK_QuestionAnswer]
        FOREIGN KEY ([AnswerId])
        REFERENCES [dbo].[Questions]
            ([QuestionId])
        ON DELETE NO ACTION ON UPDATE NO ACTION;
    GO
    
    -- Creating foreign key on [QuestionQuestionId] in table 'SubQuestions'
    ALTER TABLE [dbo].[SubQuestions]
    ADD CONSTRAINT [FK_QuestionSubQuestion]
        FOREIGN KEY ([QuestionQuestionId])
        REFERENCES [dbo].[Questions]
            ([QuestionId])
        ON DELETE NO ACTION ON UPDATE NO ACTION;
    
    -- Creating non-clustered index for FOREIGN KEY 'FK_QuestionSubQuestion'
    CREATE INDEX [IX_FK_QuestionSubQuestion]
    ON [dbo].[SubQuestions]
        ([QuestionQuestionId]);
    GO
    
    -- Creating foreign key on [SubQuestionAnswerId] in table 'SubQuestionsAnswers'
    ALTER TABLE [dbo].[SubQuestionsAnswers]
    ADD CONSTRAINT [FK_SubQuestionSubQuestionsAnswer]
        FOREIGN KEY ([SubQuestionAnswerId])
        REFERENCES [dbo].[SubQuestions]
            ([SubQuestionId])
        ON DELETE NO ACTION ON UPDATE NO ACTION;
    GO
    
    -- --------------------------------------------------
    -- Script has ended
    -- --------------------------------------------------

    I was actually making changes to foreign keys on Table "Answer" and "SubAnswer" from Table "Question", and "SubQuestion" when i encountered this problem. I have even deleted the entire database, but still from VS i don't get a prompt of "missing database" or anything along those lines. Is it i making an error or is it Visual Studio that is confused?


    There is never infinite resources.

    Thursday, August 7, 2014 4:17 AM

Answers

  • I figured it out. It is because the database actually did exist! On deleting my target database initially, and forgetting to create a new database in the Connection Properties, it pointed to the "master" database and that is where it had been pointing.

    There is never infinite resources.

    • Marked as answer by KCWamuti Monday, August 11, 2014 3:36 AM
    Monday, August 11, 2014 3:36 AM

All replies

  • Hi all. I have made some changes to a database model using model-first. After VS 2013 generates the sql file (which i expect to right click on and execute to get changes updated to my database), when i try to execute the file, i get errors such as:

    Msg 3726, Level 16, State 1, Line 50
    Could not drop object 'dbo.Users' because it is referenced by a FOREIGN KEY constraint.
    Msg 3726, Level 16, State 1, Line 53
    Could not drop object 'dbo.Answers' because it is referenced by a FOREIGN KEY constraint.
    Msg 3726, Level 16, State 1, Line 56
    Could not drop object 'dbo.Questions' because it is referenced by a FOREIGN KEY constraint.
    Msg 2714, Level 16, State 6, Line 93
    There is already an object named 'Users' in the database.
    Msg 2714, Level 16, State 6, Line 101
    There is already an object named 'Answers' in the database.
    Msg 2714, Level 16, State 6, Line 109
    There is already an object named 'Questions' in the database.
    Msg 1779, Level 16, State 0, Line 153
    Table 'Users' already has a primary key defined on it.
    Msg 1750, Level 16, State 0, Line 153
    Could not create constraint. See previous errors.
    Msg 1779, Level 16, State 0, Line 159
    Table 'Answers' already has a primary key defined on it.
    Msg 1750, Level 16, State 0, Line 159
    Could not create constraint. See previous errors.
    Msg 1779, Level 16, State 0, Line 165
    Table 'Questions' already has a primary key defined on it.
    Msg 1750, Level 16, State 0, Line 165
    Could not create constraint. See previous errors.
    Msg 1769, Level 16, State 1, Line 215
    Foreign key 'FK_SectionQuestion' references invalid column 'SectionSectionId' in referencing table 'Questions'.
    Msg 1750, Level 16, State 0, Line 215
    Could not create constraint. See previous errors.

    Below is my generated .sql file:

    -- --------------------------------------------------
    -- Entity Designer DDL Script for SQL Server 2005, 2008, 2012 and Azure
    -- --------------------------------------------------
    -- Date Created: 08/06/2014 15:59:58
    -- Generated from EDMX file: E:\My Documents\Visual Studio 2013\Projects\ExamGenerator\ExamGenerator\ExamDatabase.edmx
    -- --------------------------------------------------
    
    SET QUOTED_IDENTIFIER OFF;
    GO
    USE [master];
    GO
    IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
    GO
    
    -- --------------------------------------------------
    -- Dropping existing FOREIGN KEY constraints
    -- --------------------------------------------------
    
    IF OBJECT_ID(N'[dbo].[FK_ExamSection]', 'F') IS NOT NULL
        ALTER TABLE [dbo].[Sections] DROP CONSTRAINT [FK_ExamSection];
    GO
    IF OBJECT_ID(N'[dbo].[FK_UserExam]', 'F') IS NOT NULL
        ALTER TABLE [dbo].[Exams] DROP CONSTRAINT [FK_UserExam];
    GO
    IF OBJECT_ID(N'[dbo].[FK_SectionQuestion]', 'F') IS NOT NULL
        ALTER TABLE [dbo].[Questions] DROP CONSTRAINT [FK_SectionQuestion];
    GO
    IF OBJECT_ID(N'[dbo].[FK_QuestionAnswer]', 'F') IS NOT NULL
        ALTER TABLE [dbo].[Answers] DROP CONSTRAINT [FK_QuestionAnswer];
    GO
    IF OBJECT_ID(N'[dbo].[FK_QuestionSubQuestion]', 'F') IS NOT NULL
        ALTER TABLE [dbo].[SubQuestions] DROP CONSTRAINT [FK_QuestionSubQuestion];
    GO
    IF OBJECT_ID(N'[dbo].[FK_SubQuestionSubQuestionsAnswer]', 'F') IS NOT NULL
        ALTER TABLE [dbo].[SubQuestionsAnswers] DROP CONSTRAINT [FK_SubQuestionSubQuestionsAnswer];
    GO
    
    -- --------------------------------------------------
    -- Dropping existing tables
    -- --------------------------------------------------
    
    IF OBJECT_ID(N'[dbo].[Exams]', 'U') IS NOT NULL
        DROP TABLE [dbo].[Exams];
    GO
    IF OBJECT_ID(N'[dbo].[Sections]', 'U') IS NOT NULL
        DROP TABLE [dbo].[Sections];
    GO
    IF OBJECT_ID(N'[dbo].[Users]', 'U') IS NOT NULL
        DROP TABLE [dbo].[Users];
    GO
    IF OBJECT_ID(N'[dbo].[Answers]', 'U') IS NOT NULL
        DROP TABLE [dbo].[Answers];
    GO
    IF OBJECT_ID(N'[dbo].[Questions]', 'U') IS NOT NULL
        DROP TABLE [dbo].[Questions];
    GO
    IF OBJECT_ID(N'[dbo].[SubQuestions]', 'U') IS NOT NULL
        DROP TABLE [dbo].[SubQuestions];
    GO
    IF OBJECT_ID(N'[dbo].[SubQuestionsAnswers]', 'U') IS NOT NULL
        DROP TABLE [dbo].[SubQuestionsAnswers];
    GO
    
    -- --------------------------------------------------
    -- Creating all tables
    -- --------------------------------------------------
    
    -- Creating table 'Exams'
    CREATE TABLE [dbo].[Exams] (
        [ExamID] int IDENTITY(1,1) NOT NULL,
        [UnitCode] nvarchar(max)  NOT NULL,
        [UnitName] nvarchar(max)  NOT NULL,
        [ExamDate] nvarchar(max)  NULL,
        [Duration] float  NOT NULL,
        [Instructions] nvarchar(max)  NOT NULL,
        [University] nvarchar(max)  NOT NULL,
        [Course] nvarchar(max)  NOT NULL,
        [UserUserId] int  NOT NULL
    );
    GO
    
    -- Creating table 'Sections'
    CREATE TABLE [dbo].[Sections] (
        [SectionId] int IDENTITY(1,1) NOT NULL,
        [SectionName] nvarchar(max)  NOT NULL,
        [Marks] int  NOT NULL,
        [ExamExamID] int  NOT NULL
    );
    GO
    
    -- Creating table 'Users'
    CREATE TABLE [dbo].[Users] (
        [UserId] int IDENTITY(1,1) NOT NULL,
        [UserName] nvarchar(max)  NOT NULL,
        [Password] nvarchar(max)  NOT NULL
    );
    GO
    
    -- Creating table 'Answers'
    CREATE TABLE [dbo].[Answers] (
        [AnswerId] int  NOT NULL,
        [AnswerPhrase] nvarchar(max)  NULL,
        [Diagram] varbinary(max)  NULL
    );
    GO
    
    -- Creating table 'Questions'
    CREATE TABLE [dbo].[Questions] (
        [QuestionId] int IDENTITY(1,1) NOT NULL,
        [QuestionPhrase] nvarchar(max)  NOT NULL,
        [Diagram] varbinary(max)  NULL,
        [Marks] decimal(18,1)  NOT NULL,
        [SectionSectionId] int  NOT NULL
    );
    GO
    
    -- Creating table 'SubQuestions'
    CREATE TABLE [dbo].[SubQuestions] (
        [SubQuestionId] int IDENTITY(1,1) NOT NULL,
        [SubQuestionPhrase] nvarchar(max)  NULL,
        [Diagram] varbinary(max)  NULL,
        [Marks] decimal(18,0)  NULL,
        [QuestionQuestionId] int  NOT NULL
    );
    GO
    
    -- Creating table 'SubQuestionsAnswers'
    CREATE TABLE [dbo].[SubQuestionsAnswers] (
        [SubQuestionAnswerId] int  NOT NULL,
        [AnswerPhrase] nvarchar(max)  NULL,
        [Diagram] varbinary(max)  NULL
    );
    GO
    
    -- --------------------------------------------------
    -- Creating all PRIMARY KEY constraints
    -- --------------------------------------------------
    
    -- Creating primary key on [ExamID] in table 'Exams'
    ALTER TABLE [dbo].[Exams]
    ADD CONSTRAINT [PK_Exams]
        PRIMARY KEY CLUSTERED ([ExamID] ASC);
    GO
    
    -- Creating primary key on [SectionId] in table 'Sections'
    ALTER TABLE [dbo].[Sections]
    ADD CONSTRAINT [PK_Sections]
        PRIMARY KEY CLUSTERED ([SectionId] ASC);
    GO
    
    -- Creating primary key on [UserId] in table 'Users'
    ALTER TABLE [dbo].[Users]
    ADD CONSTRAINT [PK_Users]
        PRIMARY KEY CLUSTERED ([UserId] ASC);
    GO
    
    -- Creating primary key on [AnswerId] in table 'Answers'
    ALTER TABLE [dbo].[Answers]
    ADD CONSTRAINT [PK_Answers]
        PRIMARY KEY CLUSTERED ([AnswerId] ASC);
    GO
    
    -- Creating primary key on [QuestionId] in table 'Questions'
    ALTER TABLE [dbo].[Questions]
    ADD CONSTRAINT [PK_Questions]
        PRIMARY KEY CLUSTERED ([QuestionId] ASC);
    GO
    
    -- Creating primary key on [SubQuestionId] in table 'SubQuestions'
    ALTER TABLE [dbo].[SubQuestions]
    ADD CONSTRAINT [PK_SubQuestions]
        PRIMARY KEY CLUSTERED ([SubQuestionId] ASC);
    GO
    
    -- Creating primary key on [SubQuestionAnswerId] in table 'SubQuestionsAnswers'
    ALTER TABLE [dbo].[SubQuestionsAnswers]
    ADD CONSTRAINT [PK_SubQuestionsAnswers]
        PRIMARY KEY CLUSTERED ([SubQuestionAnswerId] ASC);
    GO
    
    -- --------------------------------------------------
    -- Creating all FOREIGN KEY constraints
    -- --------------------------------------------------
    
    -- Creating foreign key on [ExamExamID] in table 'Sections'
    ALTER TABLE [dbo].[Sections]
    ADD CONSTRAINT [FK_ExamSection]
        FOREIGN KEY ([ExamExamID])
        REFERENCES [dbo].[Exams]
            ([ExamID])
        ON DELETE NO ACTION ON UPDATE NO ACTION;
    
    -- Creating non-clustered index for FOREIGN KEY 'FK_ExamSection'
    CREATE INDEX [IX_FK_ExamSection]
    ON [dbo].[Sections]
        ([ExamExamID]);
    GO
    
    -- Creating foreign key on [UserUserId] in table 'Exams'
    ALTER TABLE [dbo].[Exams]
    ADD CONSTRAINT [FK_UserExam]
        FOREIGN KEY ([UserUserId])
        REFERENCES [dbo].[Users]
            ([UserId])
        ON DELETE NO ACTION ON UPDATE NO ACTION;
    
    -- Creating non-clustered index for FOREIGN KEY 'FK_UserExam'
    CREATE INDEX [IX_FK_UserExam]
    ON [dbo].[Exams]
        ([UserUserId]);
    GO
    
    -- Creating foreign key on [SectionSectionId] in table 'Questions'
    ALTER TABLE [dbo].[Questions]
    ADD CONSTRAINT [FK_SectionQuestion]
        FOREIGN KEY ([SectionSectionId])
        REFERENCES [dbo].[Sections]
            ([SectionId])
        ON DELETE NO ACTION ON UPDATE NO ACTION;
    
    -- Creating non-clustered index for FOREIGN KEY 'FK_SectionQuestion'
    CREATE INDEX [IX_FK_SectionQuestion]
    ON [dbo].[Questions]
        ([SectionSectionId]);
    GO
    
    -- Creating foreign key on [AnswerId] in table 'Answers'
    ALTER TABLE [dbo].[Answers]
    ADD CONSTRAINT [FK_QuestionAnswer]
        FOREIGN KEY ([AnswerId])
        REFERENCES [dbo].[Questions]
            ([QuestionId])
        ON DELETE NO ACTION ON UPDATE NO ACTION;
    GO
    
    -- Creating foreign key on [QuestionQuestionId] in table 'SubQuestions'
    ALTER TABLE [dbo].[SubQuestions]
    ADD CONSTRAINT [FK_QuestionSubQuestion]
        FOREIGN KEY ([QuestionQuestionId])
        REFERENCES [dbo].[Questions]
            ([QuestionId])
        ON DELETE NO ACTION ON UPDATE NO ACTION;
    
    -- Creating non-clustered index for FOREIGN KEY 'FK_QuestionSubQuestion'
    CREATE INDEX [IX_FK_QuestionSubQuestion]
    ON [dbo].[SubQuestions]
        ([QuestionQuestionId]);
    GO
    
    -- Creating foreign key on [SubQuestionAnswerId] in table 'SubQuestionsAnswers'
    ALTER TABLE [dbo].[SubQuestionsAnswers]
    ADD CONSTRAINT [FK_SubQuestionSubQuestionsAnswer]
        FOREIGN KEY ([SubQuestionAnswerId])
        REFERENCES [dbo].[SubQuestions]
            ([SubQuestionId])
        ON DELETE NO ACTION ON UPDATE NO ACTION;
    GO
    
    -- --------------------------------------------------
    -- Script has ended
    -- --------------------------------------------------

    I was actually making changes to foreign keys on Table "Answer" and "SubAnswer" from Table "Question", and "SubQuestion" when i encountered this problem. I have even deleted the entire database, but still from VS i don't get a prompt of "missing database" or anything along those lines. Is it i making an error or is it Visual Studio that is confused?


    There is never infinite resources.

    • Moved by Bob Beauchemin Thursday, August 7, 2014 2:25 AM Moved to a more relevant forum for best results
    • Merged by Fred BaoModerator Tuesday, August 12, 2014 9:10 AM Duplicate
    Wednesday, August 6, 2014 1:16 PM
  • You're asking a question about Entity Framework deployment, which is not the topic of this forum. Moving the question to the Entity Framework forum (http://social.msdn.microsoft.com/Forums/en-US/home?forum=adodotnetentityframework), where they'll be more likely to know the answer.

    Cheers, Bob


    Thursday, August 7, 2014 2:20 AM
  • Thanks and much apologies for posting on the wrong forum.

    There is never infinite resources.

    Thursday, August 7, 2014 4:18 AM
  • Hello,

    >>when i try to execute the file, i get errors such as:

    For the first error, it is because there are foreign key constraints existing in your current database, we cannot drop such a table by DROP syntax. Firstly, you need to clean the foreign key constraints by following this way.

    >> I have even deleted the entire database, but still from VS i don't get a prompt of "missing database" or anything along those lines

    Do you mean you meet such a dialog:

    If it is, you just need to click yes and it would generate the script for creating the database you input.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Friday, August 8, 2014 2:29 AM
    Moderator
  • Not at all. I do not get any dialog box. Just the errors listed.

    There is never infinite resources.

    Friday, August 8, 2014 8:05 AM
  • I figured it out. It is because the database actually did exist! On deleting my target database initially, and forgetting to create a new database in the Connection Properties, it pointed to the "master" database and that is where it had been pointing.

    There is never infinite resources.

    • Marked as answer by KCWamuti Monday, August 11, 2014 3:36 AM
    Monday, August 11, 2014 3:36 AM