[英]How to fix “There is already an object named ' ' in the database” error in sql server
I have created this table, I can't enter data manually because of this error. 我创建了这个表,因为这个错误我无法手动输入数据。
USE [Butterfly]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[VM_Vehicles](
[VehicleID] [nvarchar](100) NOT NULL,
[VehicleType] [nvarchar](100) NULL,
[RegistrationNo] [nvarchar](100) NULL,
[PurchaseDate] [date] NULL,
[Make] [nvarchar](100) NULL,
[Model] [nvarchar](100) NULL,
[ChassisNo] [nvarchar](100) NULL,
[EngineNo] [nvarchar](100) NULL,
[EngineCapacity] [nvarchar](100) NULL,
[YearofManufacture] [nvarchar](100) NULL,
[SeatingCapacity] [nvarchar](100) NULL,
[ContactName] [nvarchar](100) NULL,
[Phone] [nvarchar](50) NULL,
[VendorID] [int] NOT NULL,
[Picture] [image] NULL,
[VoucherNo] [int] NOT NULL,
CONSTRAINT [PK_VM_Vehicles1] PRIMARY KEY CLUSTERED
(
[VehicleID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
I have tried using this code to find what's wrong with my database. 我已经尝试使用此代码来查找我的数据库有什么问题。 so far no luck finding error.
到目前为止没有运气找错误。
IF object_id("tempdb..#VM_Vehicles") is not null
DROP TABLE #VM_Vehicles
CREATE TABLE #VM_Vehicles (vehicleID nvarchar(100), ...);
I already tried changing constraint name and table name. 我已经尝试更改约束名称和表名。 That didn't provide me a answer either.
这也没有给我一个答案。
You are creating a persistent table VM_Vehicles
in database Butterfly
. 您正在数据库
Butterfly
中创建持久性表 VM_Vehicles
。 However, you are checking a temporary table #VM_Vehicles
in database TempDB
: 但是,您正在检查数据库
TempDB
的临时表 #VM_Vehicles
:
IF object_id("tempdb..#VM_Vehicles") is not null
So you are checking another table from another database and so you have a such error: 所以你正在检查另一个数据库中的另一个表,所以你有一个这样的错误:
There is already an object named ' ' in the database
数据库中已经有一个名为''的对象
The correct check statement should look like this: 正确的检查语句应如下所示:
USE Butterfly
IF OBJECT_ID("VM_Vehicles") IS NOT NULL DROP TABLE VM_Vehicles
CREATE TABLE [dbo].[VM_Vehicles](VehicleID nvarchar(100), ...);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.