unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, DB, DBTables; type TForm1 = class(TForm) Memo1: TMemo; Button1: TButton; Button2: TButton; Button3: TButton; Query1: TQuery; Database1: TDatabase; Label1: TLabel; procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); //创建数据表 begin try with Query1 do begin close; SQL.Clear; SQL.Add('create table 学生表'); SQL.Add('(学生编号 varchar(20) not null,学生姓名 varchar(20),语文成绩 int,数学成绩 int,班主任 varchar(20))'); ExecSQL; end; Application.MessageBox('数据表创建成功。','提示',64); Except Application.MessageBox('系统出错!','提示',64); end; end; procedure TForm1.Button2Click(Sender: TObject); //删除数据表 begin try with Query1 do begin close; SQL.Clear; SQL.Add('drop table 学生表'); ExecSQL; end; Application.MessageBox('数据表删除成功。','提示',64); Except Application.MessageBox('系统出错!','提示',64); end; end; procedure TForm1.Button3Click(Sender: TObject); //退出 begin Close; end; procedure TForm1.FormCreate(Sender: TObject); begin Database1.AliasName:='DB2010'; Query1.DatabaseName:='DB2010'; end; end.
创建的数据表在哪里了呢?请看下图
大家应该猜到了,这个数据表会创建在默认的数据库里面。。。。。也就是DB2010数据库里面。