sql 按条件 删除表

Candbasic 2010-02-06 12:28:00
现有:
表a用来记录表名
id name
1 b
2 c

存在表b,
现在要删除表b: drop b,但前提是在表a中存在name='b',语句该怎么写?一句完成哦
...全文
214 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
PandaIT 2010-02-06
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 candbasic 的回复:]
有T-SQL的吗?,在C#中执行的
[/Quote]

这个就可以在C#里面运行啊!跟执行其它sql是一样的!
PandaIT 2010-02-06
  • 打赏
  • 举报
回复
if exists(select * from tableName where name='b')
drop table tableName
Candbasic 2010-02-06
  • 打赏
  • 举报
回复
有T-SQL的吗?,在C#中执行的
Snowdust 2010-02-06
  • 打赏
  • 举报
回复
Create Table a
(
[id] int not null,
[name] varchar(80) not null
)

Go

Create Table b
(
[id] int not null,
[name] varchar(80) not null
)

Go

Insert Into a([id], [name]) values(1, 'b')

Insert Into a([id], [name]) values(2, 'c')

Go

If Exists(Select 1 From a Where [name] = 'b') Drop Table b

Go
bancxc 2010-02-06
  • 打赏
  • 举报
回复
if exists(select 1 from a where name='b')
drop table b
go
蘋果虫 2010-02-06
  • 打赏
  • 举报
回复
用触发哭
ilove8 2010-02-06
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 itliyi 的回复:]
引用 1 楼 bancxc 的回复:
SQL codeifexists(select1from awhere name='b')droptable bgo
up
[/Quote]
up
itliyi 2010-02-06
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 bancxc 的回复:]
SQL codeifexists(select1from awhere name='b')droptable bgo
[/Quote]up
szyjp 2010-02-06
  • 打赏
  • 举报
回复
1楼的就可以啊
Dogfish 2010-02-06
  • 打赏
  • 举报
回复
if exists(select top 1 1 from a where name='b')
drop table b
go


一楼给答案了。在C#里分步写就行。
xhueducls 2010-02-06
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 wuyq11 的回复:]
using(SqlConnection con=new SqlConnection(""))
{
con.Open();

}
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[表名]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[表名]

[/Quote]不错
wuyq11 2010-02-06
  • 打赏
  • 举报
回复
using(SqlConnection con=new SqlConnection(""))
{
con.Open();

}
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[表名]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[表名]

111,120

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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