加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

sql-server – 如果在SQL Server中存在外键约束,我如何删除表?

发布时间:2020-12-12 08:30:35 所属栏目:MsSql教程 来源:网络整理
导读:我有以下几点: DROP TABLE [dbo].[ExtraUserInformation];DROP TABLE [dbo].[UserProfile];DROP TABLE [dbo].[webpages_Membership];DROP TABLE [dbo].[webpages_OAuthMembership];DROP TABLE [dbo].[webpages_Roles];DROP TABLE [dbo].[webpages_UsersInRol
我有以下几点:
DROP TABLE [dbo].[ExtraUserInformation];
DROP TABLE [dbo].[UserProfile];
DROP TABLE [dbo].[webpages_Membership];
DROP TABLE [dbo].[webpages_OAuthMembership];
DROP TABLE [dbo].[webpages_Roles];
DROP TABLE [dbo].[webpages_UsersInRoles];

CREATE TABLE [dbo].[ExtraUserInformation] (
    [Id]       INT            IDENTITY (1,1) NOT NULL,[UserId]   INT            NOT NULL,[FullName] NVARCHAR (MAX) NULL,[Link]     NVARCHAR (MAX) NULL,[Verified] BIT            NULL,CONSTRAINT [PK_dbo.ExtraUserInformation] PRIMARY KEY CLUSTERED ([Id] ASC)
);

CREATE TABLE [dbo].[webpages_UsersInRoles] (
    [UserId] INT NOT NULL,[RoleId] INT NOT NULL,PRIMARY KEY CLUSTERED ([UserId] ASC,[RoleId] ASC),CONSTRAINT [fk_UserId] FOREIGN KEY ([UserId]) REFERENCES [dbo].[UserProfile] ([UserId]),CONSTRAINT [fk_RoleId] FOREIGN KEY ([RoleId]) REFERENCES [dbo].[webpages_Roles] ([RoleId])
);

但是,这是一个失败的消息说:

Msg 3726,Level 16,State 1,Line 6
Could not drop object 'dbo.UserProfile' because it is referenced by a FOREIGN KEY constraint.
Msg 3726,Line 9
Could not drop object 'dbo.webpages_Roles' because it is referenced by a FOREIGN KEY constraint.
Msg 2714,State 6,Line 27
There is already an object named 'UserProfile' in the database.
Checking identity information: current identity value 'NULL',current column value 'NULL'.
DBCC execution completed. If DBCC printed error messages,contact your system administrator.

在这种情况下,我该怎么放桌子?

解决方法

您必须删除约束才能删除表.其他明智的规则违规.
如何让外键关系看到这个老问题.
SQL DROP TABLE foreign key constraint

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读