gpt4 book ai didi

sql - 创建表 : "There is already an object named ... in the database", 但未创建具有该名称的对象时出错

转载 作者:行者123 更新时间:2023-12-02 08:04:47 24 4
gpt4 key购买 nike

我正在尝试在 Microsoft SQL Server 2005 (Express) 上创建一个表。

当我运行此查询时

USE [QSWeb]
GO

/****** Object: Table [dbo].[QSW_RFQ_Log] Script Date: 03/26/2010 08:30:29 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[QSW_RFQ_Log](
[RFQ_ID] [int] NOT NULL,
[Action_Time] [datetime] NOT NULL,
[Quote_ID] [int] NULL,
[UserName] [nvarchar](256) NOT NULL,
[Action] [int] NOT NULL,
[Parameter] [int] NULL,
[Note] [varchar](255) NULL,
CONSTRAINT [QSW_RFQ_Log] PRIMARY KEY CLUSTERED
(
[RFQ_ID] ASC,
[Action_Time] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

我收到此错误消息

Msg 2714, Level 16, State 4, Line 2 There is already an object named 'QSW_RFQ_Log' in the database. Msg 1750, Level 16, State 0, Line 2 Could not create constraint. See previous errors.

但是如果我尝试使用此查询找到有问题的对象:

SELECT *
FROM QSWEB.sys.all_objects
WHERE upper(name) like upper('QSW_RFQ_%')

我明白了

(0 row(s) affected)

这是怎么回事???

最佳答案

您正在尝试创建一个与约束 (QSW_RFQ_Log) 同名的表。您的查询找不到该对象,因为表创建失败,因此该对象在错误后不存在。为约束选择一个新名称,它将起作用,例如:

CONSTRAINT [QSW_RFQ_Log_PK] PRIMARY KEY CLUSTERED

关于sql - 创建表 : "There is already an object named ... in the database", 但未创建具有该名称的对象时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2523397/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com