当前位置:主页>仓库管理软件> 列表

如何检查表中是否已经存在一个字段?

销售管理软件版1楼: 如何检查表中是否已经存在一个字段?
比如 对于表a 如何检查是否有字段ca

如果有不增加,没有增加该字段

2楼: for i:=0 to Query1.Fields.count-1 do
if Query1.Fields[i].name=''ca'' then
begin
....
end; 如金碟财务软件官网

3楼: if qry2.FieldList.Find(''字段名'') = nil then
ShowMessage(''nil'');

4楼: 你是要对客户端程序进行升级吧
try
select field from table
except
alert table field nvarchar(39)
end
不就行了吧

5楼: if query1.findfield(''字段名'') = nil then
showmessage(''不存在这个字段'');

6楼: 同意YUD的答案

销售管理软件版7楼: shine007的方法省事

8楼: 是 SNVAY 的意思

好像语句有错误!

9楼: SQL语句:
if not exists (select * from dbo.syscolumns where id = object_id(N''表名'') and name = ''字段名'')
alter table 表名
add 字段名 字段数据类型

运用:
const
ConnStr = ''if not exists (select * from dbo.syscolumns where id = object_id(N''''%s'''') and name = ''''%s'''') alter table %s add %s %s'';

ADOQuery1.SQL.Text := format(Connstr,[''t_n'',''f_n'',''t_n'',''f_n'',''varchar(10)'']);
ADOQuery1.ExecSQL;

10楼: 太感谢了