Quantcast
Channel: SQL Server Manageability forum
Viewing all articles
Browse latest Browse all 1519

Object already exists

$
0
0

I am having a problem creating a table and have tried everything I can find to resolve it on the internet. I'm sure there's an explanation, but I just can't figure it out. I am dropping and creating all user tables on a database.  The other tables I'm creating that are using the same pattern work fine. Any ideas on what I'm doing wrong? Here is the code I am running to drop/create the table, followed by the error that is returned:

/*

 * TABLE: AspNetUsers

 */

IFOBJECT_ID('AspNetUsers')ISNOT NULL

BEGIN

    DROPTABLEAspNetUsers

    PRINT'<<< DROPPED TABLE AspNetUsers >>>'

END

go

CREATETABLEAspNetUsers(

    Id                     nvarchar(128)   NOTNULL,

    Email                  nvarchar(256)   NULL,

    EmailConfirmed          bit             NOTNULL,

    PasswordHash           nvarchar(max)   NULL,

    SecurityStamp           nvarchar(max)   NULL,

    PhoneNumber            nvarchar(max)   NULL,

    PhoneNumberConfirmed    bit             NOTNULL,

    TwoFactorEnabled        bit             NOTNULL,

    LockoutEndDateUtc       datetime         NULL,

    LockoutEnabled          bit             NOTNULL,

    AccessFailedCount       int             NOTNULL,

    UserName               nvarchar(256)   NOTNULL,

    CONSTRAINTAspNetUsers PRIMARYKEYCLUSTERED(Id)

)

go

IFOBJECT_ID('AspNetUsers')ISNOT NULL

    PRINT'<<< CREATED TABLE AspNetUsers >>>'

ELSE

    PRINT'<<< FAILED CREATING TABLE AspNetUsers >>>'

go

Here is the result:

Msg 2714, Level 16, State 5, Line 3

There is already an object named 'AspNetUsers' in the database.

Msg 1750, Level 16, State 0, Line 3

Could not create constraint. See previous errors.

<<< FAILED CREATING TABLE AspNetUsers >>>

I get no rows returned when I run these queries:

SELECT *

  FROM sys.sysobjects

 WHERE Name like '%AspNetUsers%'

SELECT *

  FROM sys.all_objects

 WHERE Name like '%AspNetUsers%'

And these queries do not return any rows with these objects either:

SELECT *

  FROM sys.all_objects

SELECT *

  FROM sys.sysobjects



Viewing all articles
Browse latest Browse all 1519

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>