delphi里如何索引?如何删除表?
请问下列语句错在哪里?怎样才是正确的?谢了
adoquery1.sql.add('create index zzz on baocan(xm,rq)'); //运行出错
adoquery1.execsql;
adoquery1.sql.add('drop table baocan');
adoquery1.execsql;
以上命令在SQL查询器里运行正常,但是在delphi里就报错,是不是SQL命令只有少数几个命令(如:select ,update,delete)才能在SQL里运行呢?其它的命令要通过过程存储才能实现?
[解决办法]
在DELPHI中大家一般都是使用ADO组件,当然需要你构造一个SQL语句。
第一个IF返回的结果用来控制代码的下一步的流程。。
成delphi句:
- SQL code
if exists(select 1 from sysobjects where xtype = 'U ' and id = Object_id(N 'tablename ')) then drop table tablename; else create table tablename();
[解决办法]
先连接好数据库
- Delphi(Pascal) code
adoquery1.close;adoquery1.sql.clear;adoquery1.sql.add('create table 表名( 学号 char(20),姓名 char(20),班级 char(20))');adoquery1.execsql;
[解决办法]
删除表?
试试:
adoquery1.close;
adoquery1.sql.clear;
adoquery1.sql.add(drop table table_name');
adoquery1.execsql;