我只想保留SQL 表 F_ID 一个字段﹐其它全部删除。动态的请问怎幺做呀﹖

Ngg 2005-02-19 11:54:02
同上~~谢谢
...全文
65 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
chinaandys 2005-02-19
  • 打赏
  • 举报
回复
Sorry,已经测试:
------------
declare @i int, @Col varchar(50)
select @i=count(*) from syscolumns where id=object_id('表名') and [name]<>'F_ID'

while @i>0
begin
select @Col=[name] from syscolumns where id=object_id('表名') and [name]<>'F_ID'
exec('alter table 表名 drop column '+@Col+'')
set @i=@i-1
end
go
chinaandys 2005-02-19
  • 打赏
  • 举报
回复
搞错修改一下:

declare @i int,@Col varchar(50)
select @i=count(*) from syscolumns where id=object_id('test') and name<>'F_ID'

while @i>0
begin
select @Col=name from syscolumns where id=object_id('test') and name<>'F_ID'
alter table 表名
drop columns @Col
set @i=@i-1
end
go
chinaandys 2005-02-19
  • 打赏
  • 举报
回复
到查询分析器或写成存储过程去执行

declare @i int,@Col varchar(50)
select @i=count(*) from syscolumns where id=object_id('test') where name<>'F_ID'

while @i>0
begin
select @Col=name from syscolumns where id=object_id('test') and name<>'F_ID'
alter table 表名
drop columns @Col
set @i=@i-1
end
go
firstshine 2005-02-19
  • 打赏
  • 举报
回复
你要用到数据字典,找到该表的所有字段,删除不是f_id的所有字段,各种数据库的数据字典不一样,还要看你是什么样的数据库
zhangl_cn 2005-02-19
  • 打赏
  • 举报
回复
用SQL语句

2,497

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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