怎样在delphi新建数据库表

解决方案 »

  1.   

    ado+ adocommand
    SQL:=‘create table()’
    具体看帮助
      

  2.   

    adoquery或adocommand,用Sql语句
    如:Create Table file (id  AutoIncrement PRIMARY KEY,ChannelNo Smallint,Filename char(21) not null,StartDate datetime not null,TimeLength char(8),Mode smallint,OtherTel char(128),Re char(200),FileSort Smallint,Listen bit,Importance bit)
      

  3.   

    下面是一个例子:
    procedure CreateATable;
    var
      tbl : TTable;
    begin
      tbl := TTable.Create(Application);
      with tbl do begin
        Active := False;
        DatabaseName := '';
        TableName := '';
        TableType := ttParadox;
        with FieldDefs do begin
          Clear;
          Add('LastName', ftString, 30, False);
          Add('FirstName', ftString, 30, False);
          Add('Address1', ftString, 40, False);
          Add('Address2', ftString, 40, False);
          Add('City', ftString, 30, False);
          Add('ST', ftString, 2, False);
          Add('Zip', ftString, 10, False);
        end;    {Add a Primary Key to the table}
        with IndexDefs do begin
          Clear;
          Add('Field1Index', 'LastName;FirstName', [ixPrimary, ixUnique]);
        end;
        
        CreateTable; {Make the table}
      end;
    end;
      

  4.   

    Query1.close;
    Query1.sql.clear;
    Query1.sql.add('crate table myNew(aa number(3),bb varchar(20),primary key(aa))');
    Query1.execsql;新建表myNew,字段aa,bb,主码为aa
      

  5.   

    with TADOQuery.create(nil) do
      begin
        connection:=ADOConnection1;
        //or connectionstring:='...';
       sql.text:='create table mytable (a char(1),b int                (4),PRIMARYkEY                (a))';
       execsql;   
      end;向您学习,向你们学习。
      

  6.   


    begin
     try
       Querycreatetable:=Tadoquery.create(nil)
       Querycreatetable.connection:=ADOCConnection1;
       Querycreatetable.close;
       Querycreatetable.sql.clear; 
       Querycreate.sql.add('crate table myNew(aa number(3),bb varchar (20),primary key(aa))');
       Querycreate.execsql;
      except
        application.message('发生错误',‘不能创建表',MB_OK);
    end;