我已经创建了这个表,由于这个错误,我无法手动输入数据。
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
我已经尝试使用此代码来查找数据库的错误。到目前为止还没有发现运气错误。
IF object_id("tempdb..#VM_Vehicles") is not null
DROP TABLE #VM_Vehicles
CREATE TABLE #VM_Vehicles (vehicleID nvarchar(100), ...);
我已经尝试更改约束名称和表名称。这也没有给我一个答案。
您正在数据库Butterfly
中创建一个持久表VM_Vehicles
。但是,您正在检查数据库TempDB
:中的临时表#VM_Vehicles
IF object_id("tempdb..#VM_Vehicles") is not null
因此,您正在从另一个数据库中检查另一个表,因此出现了这样的错误:
数据库中已经有一个名为"的对象
正确的检查语句应该如下所示:
USE Butterfly
IF OBJECT_ID("VM_Vehicles") IS NOT NULL DROP TABLE VM_Vehicles
CREATE TABLE [dbo].[VM_Vehicles](VehicleID nvarchar(100), ...);