delphi判断MSSQL数据库中表格是否存在? 如何批量创建表格?  
官方Delphi 学习QQ群: 682628230(三千人)
频道

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;

推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.04315185546875 seconds