locked
Error while Creating a table in Sql server managment studio RRS feed

  • Question

  • hi

    i am creating a table but while executing that table it is showing this error

    Msg 1767, Level 16, State 0, Line 1
    Foreign key 'FK_Statutory_Form_Group_Lookup-Statutory_Form_Lookup' references invalid table 'Statutory_Form_Group_Lookup'.
    Msg 1750, Level 16, State 0, Line 1
    Could not create constraint. See previous errors.

    I am creating this table for 1st time

    Tuesday, February 26, 2013 6:13 AM

Answers

  • thanx for your help but i dont no how but the code is exuted corectly
    • Marked as answer by lucky1527 Tuesday, February 26, 2013 6:43 AM
    Tuesday, February 26, 2013 6:43 AM

All replies

  • I can reproduce this easily. You are referencing to not exist table.... Create table Statutory_Form_Group_Lookup first....

    create table t (c int not null primary key, fk int foreign key references noexists(c))

    Msg 1767, Level 16, State 0, Line 1
    Foreign key 'FK__t__fk__55DFB4D9' references invalid table 'noexists'.
    Msg 1750, Level 16, State 0, Line 1
    Could not create constraint. See previous errors.


    Best Regards,Uri Dimant SQL Server MVP, http://sqlblog.com/blogs/uri_dimant/

    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Blog: Large scale of database and data cleansing
    Remote DBA Services: Improves MS SQL Database Performance

    Tuesday, February 26, 2013 6:17 AM
  • i have created that table first then this one
    Tuesday, February 26, 2013 6:19 AM
  • this is my code

    CREATE TABLE [dbo].[Statutory_Form_Group_Lookup](
        [Statutory_Form_Group_ID] [int] IDENTITY(1,1) NOT NULL,
        [Statutory_Form_Group_Name] [nvarchar](128) NOT NULL,
       
     CONSTRAINT [PK_Statutory_Form_Group_Lookup] PRIMARY KEY CLUSTERED (Statutory_Form_Group_ID)
     )
     GO
     
     CREATE TABLE [dbo].[Statutory_Form_Lookup](
        [Statutory_Form_ID] [int] IDENTITY(1,1) NOT NULL,
        [Statutory_Form_Name] [nvarchar] (256) NOT NULL,
        [Statutory_Form_Group_ID] [int] NOT NULL,
       
        CONSTRAINT [PK_Payee_Type_Lookup] PRIMARY KEY CLUSTERED (Statutory_Form_ID),
        CONSTRAINT [FK_Statutory_Form_Group_Lookup-Statutory_Form_Lookup] FOREIGN KEY (Statutory_Form_Group_ID) REFERENCES Statutory_Form_Group_Lookup(Statutory_Form_Group_ID)
    )
    GO

    Tuesday, February 26, 2013 6:20 AM
  • this is my code

    CREATE TABLE [dbo].[Statutory_Form_Group_Lookup](
        [Statutory_Form_Group_ID] [int] IDENTITY(1,1) NOT NULL,
        [Statutory_Form_Group_Name] [nvarchar](128) NOT NULL,
       
     CONSTRAINT [PK_Statutory_Form_Group_Lookup] PRIMARY KEY CLUSTERED (Statutory_Form_Group_ID)
     )
     GO
     
     CREATE TABLE [dbo].[Statutory_Form_Lookup](
        [Statutory_Form_ID] [int] IDENTITY(1,1) NOT NULL,
        [Statutory_Form_Name] [nvarchar] (256) NOT NULL,
        [Statutory_Form_Group_ID] [int] NOT NULL,
       
        CONSTRAINT [PK_Payee_Type_Lookup] PRIMARY KEY CLUSTERED (Statutory_Form_ID),
        CONSTRAINT [FK_Statutory_Form_Group_Lookup-Statutory_Form_Lookup] FOREIGN KEY (Statutory_Form_Group_ID) REFERENCES Statutory_Form_Group_Lookup(Statutory_Form_Group_ID)
    )
    GO

    This code executed well on my box here...make sure you are in same database context.. Add

    USE [MYdatabase]

    GO

    <<put your code here>> and execute it...


    Hope it Helps!!

    Tuesday, February 26, 2013 6:29 AM
  • Are you sure that you execute this script under 'right' database?

    Best Regards,Uri Dimant SQL Server MVP, http://sqlblog.com/blogs/uri_dimant/

    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Blog: Large scale of database and data cleansing
    Remote DBA Services: Improves MS SQL Database Performance

    Tuesday, February 26, 2013 6:41 AM
  • thanx for your help but i dont no how but the code is exuted corectly
    • Marked as answer by lucky1527 Tuesday, February 26, 2013 6:43 AM
    Tuesday, February 26, 2013 6:43 AM