在DELPHI中如何将将原有的一个标准的数据库复制成另一个数据库(包括表,VIEW,存贮过程,及所设置好的所有权限等信息)

解决方案 »

  1.   

    //下面是一个导出表的函数 一次导出一个表sql->access
    //复制数据库 如果是sql 建议用 备份和恢复
    function tform1.outdata(tab:string):boolean;//tab为表名 
    //我的两个表名都是一样的 不知道你的是不是 我是实现从 sql->access
    var p_adoquery,adoquery1:tadoquery;
    i:integer;
    begin
    try
    //p_adoquery为要导出的数据表 adoquery1为导出到的数据表 
    p_adoquery:=tadoquery.create(nil);
    p_adoquery.Connection:=adoconn;//初始化查询 adoconn为sql连接
    p_adoquery.SQL.Clear;
    p_adoquery.SQL.Add('select * from '+tab);
    try
    p_adoquery.Open;
    except
    messagebox(handle,'数据查询出错!','提示',mb_iconerror);
    exit;
    end;
    //adoquery1:=tadoquery.create(nil);
    adoquery1.Connection:=adoconn1;//初始化查询adoconn1为access连接 
    adoquery1.SQL.Clear;
      adoquery1.SQL.Add('delete  from '+tab);
       adoquery1.ExecSQL;   //原表有数据就清空 adoquery1.Close;
      adoquery1.SQL.Clear;
      adoquery1.SQL.Add('select * from '+tab);
     adoquery1.ParamCheck:=false;
       adoquery1.open;while(not p_adoquery.Eof) do //一条 一条的导
    begin
     adoquery1.Insert;
    //注意如果你是要导出到sql的话 如果是递增的标识 那就有点麻烦了
    //sql递增标识不允许操作 access允许 呵呵~~
      for i:=0 to p_adoquery.FieldList.Count-1 do  
        begin
    adoquery1.FieldByName(p_adoquery.FieldList.Fields[i].FieldName).Value:=p_adoquery.FieldByName(p_adoquery.FieldList.Fields[i].FieldName).Value;
    end;
      try
        adoquery1.Post;
         application.ProcessMessages;
       except
        p_adoquery.Next;
        continue;
       end;
    p_adoquery.Next;
    end;
    finally
    p_adoquery.Close;
    p_adoquery.free;
    adoquery1.Close;
    adoquery1.free;
     application.ProcessMessages;
    end;
    end;
    //[email protected] 有问题直接给我写信