怎样删除一个表呢?用什么语句?

youngby 2003-11-25 10:52:53
表如下:
create Table dbo.EmployeeMgrExamployee1
(
EmpID int identity(1,1) not null primary key clustered,
SSN char(10) not null unique nonclustered,
LastName varchar(20) not null,
FirstName varchar(20) not null,
Gender char(1) null,
JobTitle varchar(20) null
,
MgrId int Not null
references dbo.EmployeeMgrExamployee1(EmpID))

...全文
31 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
pengdali 2003-11-25
  • 打赏
  • 举报
回复
drop table EmployeeMgrExamployee1


就可以了
shuiniu 2003-11-25
  • 打赏
  • 举报
回复
要先删FK再删PK!!!
shuiniu 2003-11-25
  • 打赏
  • 举报
回复
declare @myPk sysname
declare @myfk sysname
select @myPk=c.name from syscolumns a,sysconstraints b,sysobjects c
where a.id=object_id('EmployeeMgrExamployee1') and a.name='EmpID' and
a.id=b.id and b.constid=c.id and c.name like 'PK%'

select @myFk=c.name from syscolumns a,sysconstraints b,sysobjects c
where a.id=object_id('EmployeeMgrExamployee1') and a.name='MgrId' and
a.id=b.id and b.constid=c.id and c.name like 'fK%'

if @myFk is not null and @myFk<> ''
begin
exec('alter table EmployeeMgrExamployee1
drop constraint ' +@myFk)
end
if @myPk is not null and @myPk<> ''
begin
exec('alter table EmployeeMgrExamployee1
drop constraint ' + @myPk )
end
drop table EmployeeMgrExamployee1
lynx1111 2003-11-25
  • 打赏
  • 举报
回复
try:
declare @myPk sysname
declare @myfk sysname
declare @str1 varchar(200)
declare @str2 varchar(200)
select @myPk=c.name from syscolumns a,sysconstraints b,sysobjects c
where a.id=object_id('EmployeeMgrExamployee1') and a.name='EmpID' and
a.id=b.id and b.constid=c.id and c.name like 'PK%'

select @myFk=c.name from syscolumns a,sysconstraints b,sysobjects c
where a.id=object_id('EmployeeMgrExamployee1') and a.name='MgrId' and
a.id=b.id and b.constid=c.id and c.name like 'fK%'

if @myPk is not null and @myPk<> ''
begin
set @str1='alter table EmployeeMgrExamployee1 drop constraint'+ @myPk
exec (@str1)
end
if @myPk is not null and @myPk<> ''
begin
set @str2='alter table EmployeeMgrExamployee1 drop constraint'+ @myFk
exec (@str2)
end
drop table EmployeeMgrExamployee1
youngby 2003-11-25
  • 打赏
  • 举报
回复
declare @myPk sysname
declare @myfk sysname
select @myPk=c.name from syscolumns a,sysconstraints b,sysobjects c
where a.id=object_id('EmployeeMgrExamployee1') and a.name='EmpID' and
a.id=b.id and b.constid=c.id and c.name like 'PK%'

select @myFk=c.name from syscolumns a,sysconstraints b,sysobjects c
where a.id=object_id('EmployeeMgrExamployee1') and a.name='MgrId' and
a.id=b.id and b.constid=c.id and c.name like 'fK%'

if @myPk is not null and @myPk<> ''
begin
alter table EmployeeMgrExamployee1
drop constraint @myPk
end
if @myPk is not null and @myPk<> ''
begin
alter table EmployeeMgrExamployee1
drop constraint @myFk
end
drop table EmployeeMgrExamployee1


有错误,,请问如何改正??

55555
没有分了。
请帮忙。

34,623

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧