sql – 创建表时出错:“数据库中已经有一个名为…的对象”,但不是该名称的对象

前端之家收集整理的这篇文章主要介绍了sql – 创建表时出错:“数据库中已经有一个名为…的对象”,但不是该名称的对象前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图在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,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

猜你在找的MsSQL相关文章