怎样用DELPHI在SQL2000里创建数据库?该用什么控件?
我曾经使用SQLCONNECTION 和SQL Query写,但没有成功!

解决方案 »

  1.   

    PARADOX 数据库:
    with Table1 do begin
      Active := False;  
      DatabaseName := 'DBDEMOS';
      TableType := ttParadox;
      TableName := 'CustInfo';  { Don't overwrite an existing table }  if not Table1.Exists then begin
        { The Table component must not be active }
        { First, describe the type of table and give }
        { it a name }
        { Next, describe the fields in the table }
        with FieldDefs do begin
          Clear;
          with AddFieldDef do begin
            Name := 'Field1';
            DataType := ftInteger;
            Required := True;
          end;
          with AddFieldDef do begin        Name := 'Field2';
            DataType := ftString;
            Size := 30;
          end;
        end;
        { Next, describe any indexes }
        with IndexDefs do begin
          Clear;
          { The 1st index has no name because it is
          { a Paradox primary key }
          with AddIndexDef do begin
            Name := '';
            Fields := 'Field1';
            Options := [ixPrimary];
          end;
          with AddIndexDef do begin        Name := 'Fld2Indx';
            Fields := 'Field2';
            Options := [ixCaseInsensitive];
          end;
        end;
        { Call the CreateTable method to create the table }
        CreateTable;
      end;
    end;
      

  2.   

    Table, Query, AdoTable, AdoQuery都可以的。直接写Sql语句。
    你用SQLCONNECTION 和SQL Query写为什么不行呢,贴出来看看
      

  3.   

    用SQLCONNECTION 和 SQL QUERY写,先将SQLCONNECTION连接到SQL数据库中的某一个表,再写SQL语句:use master
          go
          .....
          go
    但总是提示语法错误!
      

  4.   

    const
      SConnectionString = 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%s;'
        + 'Jet OLEDB:Database Password=%s;';function GetTempPathFileName(): string;
    var
      SPath, SFile: array[0..254] of char;
    begin
      GetTempPath(254, SPath);
      GetTempFileName(SPath, '~SM', 0, SFile);
      result := SFile;
      DeleteFile(result);
    end;//这里是关键
    function CreateAccessFile(FileName: string; PassWord: string = ''): boolean;
    var
      STempFileName: string;
      vCatalog: OleVariant;
    begin
      STempFileName := GetTempPathFileName;
      try
        vCatalog := CreateOleObject('ADOX.Catalog');
        vCatalog.Create(format(SConnectionString, [STempFileName, PassWord]));
        result := CopyFile(PChar(STempFileName), PChar(FileName), True);
        DeleteFile(STempFileName);
      except
        result := false;
      end;
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
      CreateAccessFile('C:\aa.mdb');
    end;
      

  5.   

    直接连接到数据库的master库,最好用sa用户,然后运行创建数据库的语句,创建数据库的时间需要给出数据库文件所在的路径,因此可能还需要使用系统存储过程来获取相应的数据库存放的路径。