delphi判断MSSQL数据库中表格是否存在? 如何批量创建表格?


本文整理自网络,侵删。

 function TableExists(TableName:string):Boolean;
var
str:string;
begin
str:='SELECT * FROM sysobjects WHERE name ='+''''+TableName+'''';
DM.qry1.Close;
DM.qry1.SQL.Clear;
DM.qry1.SQL.Add(str);
DM.qry1.ExecSQL(False);
if DM.qry1.RecordCount=1 then
Result:=True
else
Result:=False;
end;



procedure CreateTable(TableName:string);
const
SQL='CREATE TABLE [dbo].[TABLE1] ( '+
' [RQ] [datetime] NOT NULL , '+
' [RGZ] [char] (4) COLLATE Chinese_PRC_CI_AS NULL , ' +
' [Sun] [real] NULL , ' +
' [Moon] [real] NULL , '+
' [UD] [real] NULL , '+
' [O] [decimal](8, 2) NULL , '+
' [H] [decimal](8, 2) NULL , '+
' [L] [decimal](8, 2) NULL , ' +
' [C] [decimal](8, 2) NULL , ' +
' [JE] [bigint] NULL , ' +
' [V] [bigint] NULL ) ON [PRIMARY]';
var
str:string;
begin
str:=StringReplace(SQL,'[dbo].[TABLE1]',TableName,[rfReplaceAll]);
DM.qry1.Close;
DM.qry1.SQL.Clear;
DM.qry1.SQL.Add(str);
DM.qry1.ExecSQL(false);
end;

相关阅读 >>

Delphi 相对路径

Delphi 有关debughook

Delphi 在ms access数据库中图像的存储和显示

Delphi 利用Delphi监视注册表的变化

Delphi 取windows登录用户名

Delphi ado 连接mssql数据库

Delphi fmx窗体中控件对齐方式介绍

Delphi 采集功能代码getstr

winapi 字符及字符串函数(9): lstrcat - 合并字符串

Delphi tlist性能注意事项

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...