删除表

jackluo1981 2004-08-11 04:55:02
我想删除创建时间是今天的用户表,SQL语句怎么写?
...全文
209 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
pbsql 2004-08-12
  • 打赏
  • 举报
回复
是的
jackluo1981 2004-08-12
  • 打赏
  • 举报
回复
to to pbsql(风云):
非常感谢,你是对的,但我还有一点不明白就是下面的代码结果为什么是许多条一样的结果?
declare @t varchar(100),@n int
select @n=count(*) from sysobjects where xtype='U' and datediff(day,crdate,getdate())=0
while @n>0
begin
select @t=name from sysobjects where xtype='U' and datediff(day,crdate,getdate())=0
select @t
set @n=@n-1
end
是不是
select @t=name from sysobjects where xtype='U' and datediff(day,crdate,getdate())=0
这句话每次选出来的是最前面的一个?
pbsql 2004-08-12
  • 打赏
  • 举报
回复
你错了:
declare @t varchar(100),@n int
select @n=count(*) from sysobjects where xtype='U' and datediff(day,crdate,getdate())=0
while @n>0
begin
select @t=name from sysobjects where xtype='U' and datediff(day,crdate,getdate())=0
exec('drop table '+@t)
set @n=@n-1
end
jackluo1981 2004-08-12
  • 打赏
  • 举报
回复
我想我现在知道错在哪了?select name from sysobjects where xtype='U' and datediff(day,crdate,getdate())=0
结果本来就是一个集合,是不能付值给一个变量.
jackluo1981 2004-08-12
  • 打赏
  • 举报
回复
用上面的代码是结果全为'Rate',谁能不能在自己的机子上试一下,看结果怎么样?
jackluo1981 2004-08-12
  • 打赏
  • 举报
回复

declare @t varchar(100),@n int
select @n=count(*) from sysobjects where xtype='U' and datediff(day,crdate,getdate())=0
while @n>0
begin
select name from sysobjects where xtype='U' and datediff(day,crdate,getdate())=0
set @n=@n-1
end
还是一样呀!!!!!!!
pbsql 2004-08-12
  • 打赏
  • 举报
回复
低级错误:@t没有定义长度
hglhyy 2004-08-12
  • 打赏
  • 举报
回复
select name from sysobjects
where datediff(day,crdate,getdate())>0 and xtype='u' and status>=0
jackluo1981 2004-08-12
  • 打赏
  • 举报
回复
to to pbsql(风云):
但还是不对,我用下面的代码测试:
declare @t varchar,@n int
select @n=count(*) from sysobjects where xtype='U' and datediff(day,crdate,getdate())=0
while @n>0
begin
select name from sysobjects where xtype='U' and datediff(day,crdate,getdate())=0
set @n=@n-1
end
时看见结果都是是我想要的表名;但用下面的代码时
eclare @t varchar,@n int
select @n=count(*) from sysobjects where xtype='u' and datediff(day,crdate,getdate())=0
while @n>0
begin
select @t=name from sysobjects where xtype='U' and datediff(day,crdate,getdate())=0
select @t
set @n=@n-1
end
结果都变成了'R',真的搞不懂为什么?
rouqu 2004-08-12
  • 打赏
  • 举报
回复
use yourdb
go
select name from sysobjects
where xtype = 'u' and status >= 0 --查看用户表
and datediff(day,crdate,getdate()) = 0 --筛选出今天用户表
pbsql 2004-08-12
  • 打赏
  • 举报
回复
如果你数据库的排序规则不区分大小写,那段程序是对的,否则就不对了(注意'u'、'U')
jackluo1981 2004-08-12
  • 打赏
  • 举报
回复
up
jackluo1981 2004-08-12
  • 打赏
  • 举报
回复
to pbsql(风云):
当有很多条时,我用
eclare @t varchar,@n int
select @n=count(*) from sysobjects where xtype='u' and datediff(day,crdate,getdate())=0
while @n>0
begin
select @t=name from sysobjects where xtype='U' and datediff(day,crdate,getdate())=0
exec('drop table '+@t)
set @n=@n-1
end
为什么不对?
skyboy0720 2004-08-11
  • 打赏
  • 举报
回复
--查询出今天创建的表

select name from sysobjects where datediff(day,crdate,getdate())>0 and xtype='u' and status>=0
WangZWang 2004-08-11
  • 打赏
  • 举报
回复
declare @tblname varchar(30)
declare cursorName cursor
for
Select Name from sysobjects
where Xtype='U' and
datediff(day,crdate,getdate())=0
open cursorName
fetch next from cursorName into @tblname
while @@fetch_status=0
begin
exec('drop table '+@tblname)
fetch next from cursorName into @tblname
end
close cursorName
deallocate cursorName
sankis 2004-08-11
  • 打赏
  • 举报
回复
delete from 表 where date = getdate()
pbsql 2004-08-11
  • 打赏
  • 举报
回复
declare @tb varchar(100)
if exists(select * from sysobjects where xtype='U' and datediff(day,crdate,getdate())=0)
begin
select @tb=name from sysobjects where xtype='U' and datediff(day,crdate,getdate())=0
exec('drop table '+@tb)
end

34,575

社区成员

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

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