本来我是这样写的:
begin
adoquery.SQL.Text := 'select top 1 * from tablename';
adoquery.Open;
try
adoquery.FieldByName('id').FocusControl;
except
begin
adoquery.SQL.Text := 'alter table tablename add id IDENTITY(1,1) PRIMARY KEY ';
adoquery.ExecSQL;
end;
end;
end;
在不是主键的字段不会出问题,但是在主键字段就会出问题,还有怎么删除主键,然后再赋值给别的字段!???
begin
adoquery.SQL.Text := 'select top 1 * from tablename';
adoquery.Open;
try
adoquery.FieldByName('id').FocusControl;
except
begin
adoquery.SQL.Text := 'alter table tablename add id IDENTITY(1,1) PRIMARY KEY ';
adoquery.ExecSQL;
end;
end;
end;
在不是主键的字段不会出问题,但是在主键字段就会出问题,还有怎么删除主键,然后再赋值给别的字段!???
解决方案 »
- 问一些理论问题
- 我使用dxBarManager时出现的怪现象
- 请教这样一个sql怎么写?
- 这一种界面是怎么做出来的?
- 急救!!!!!
- 关于MS-SOL SQL Server的加锁问题
- 自编脚本语言解释器
- 菜鸟继续提问,大家来看看也好,谢谢!
- opendriver函数的使用方法。
- 真奇怪,谁做过李维的《分布式多层应用系统篇》2-1-6Master/Detail,为什么我在客户端加入第二个ClientDataSet时ClientDataSet2.DataSetField不能设置为ClientDataSet1.adsDetail?
- 如何学习用Delphi写串口程序?请各位指教!!!!!加分多多!!!
- 遍历dbgrid数据行怎样提高速度
procedure check(sColumn,sTable:String):Boolean;
var
sSql:string;
dtst:TClientDataset;//也可以用adoquery,query等等
begin
sSql:='select column_name from all_cons_columns where '+
'table_name='''+sTable+''' and constraint_name=('+
'select constraint_name '+
'from 'all_constraints where owner=''YXGL'''+
' and table_name='''+stable+''' and constraint_type=''P'''+
') order by position';
//在这里加几条语句把sSql检索到dtst中
if dtst.Locate('column_name',sColumn,[]) then
result:=true
else
Result:=false;
end;