Студенты | Сессия | Предмет |
---|---|---|
Код студента | Код студента | Код предмета |
Группа | Код предмета | Наименование предмета |
ФИО | Оценка | ФИО преподавателя |
Курс | Дата экзамена | |
Пол | ||
Дата рождения | ||
Форма обучения |
Создадим БД в C:\dbase1\STUDENTS.GDB . Запускаем IBConsole.exe . Далее:
CREATE TABLE "STUD" ( "KODSTUD" SMALLINT NOT NULL, "GRUP" CHAR(10) CHARACTER SET WIN1251 NOT NULL COLLATE PXW_CYRL, "FIO" CHAR(30) CHARACTER SET WIN1251 NOT NULL COLLATE PXW_CYRL, "KURS" SMALLINT NOT NULL, "POL" CHAR(1) CHARACTER SET WIN1251 NOT NULL, "DATROJD" DATE NOT NULL, "FORMA" CHAR(10) CHARACTER SET WIN1251 NOT NULL COLLATE PXW_CYRL, PRIMARY KEY ("KODSTUD") ); CREATE TABLE "PREDMET" ( "KODPREDM" SMALLINT NOT NULL, "NAZVAN" CHAR(20) CHARACTER SET WIN1251 NOT NULL COLLATE PXW_CYRL, "FIO" CHAR(30) CHARACTER SET WIN1251 NOT NULL COLLATE PXW_CYRL, PRIMARY KEY ("KODPREDM") ); CREATE TABLE "SESS" ( "KODSTUD" SMALLINT NOT NULL, "KODPREDM" SMALLINT NOT NULL, "OCENKA" SMALLINT NOT NULL, "DATEKZ" DATE NOT NULL ); ALTER TABLE "SESS" ADD FOREIGN KEY ("KODSTUD") REFERENCES STUD ("KODSTUD");Для ввода запросов: Меню | Tools | Interacive SQL.
Для просмотра данных используется 2 способа:
procedure TForm1.N8Click(Sender: TObject); begin IBTable1.Active:=false; IBTable1.TableName:='PREDMET'; IBTable1.IndexFieldNames:='KODPREDM'; DataSource1.DataSet:= IBTable1; IBTable1.Active:=true; end;
procedure TForm1.N4Click(Sender: TObject); begin IBTable1.Active:= false; IBQuery1.Active:=false; IBQuery1.SQL.Clear; IBQuery1.SQL.Append('select * from stud order by forma, grup, fio'); IBQuery1.Active:=true; DataSource1.DataSet:=IBQuery1; end;
unit unStud; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Menus, ExtCtrls, DBCtrls, Grids, DBGrids, DB, IBQuery, IBCustomDataSet, IBTable, IBDatabase, StdCtrls; type TForm1 = class(TForm) IBDatabase1: TIBDatabase; IBTransaction1: TIBTransaction; IBTable1: TIBTable; IBQuery1: TIBQuery; DataSource1: TDataSource; DBGrid1: TDBGrid; DBNavigator1: TDBNavigator; MainMenu1: TMainMenu; N1: TMenuItem; N2: TMenuItem; N3: TMenuItem; N4: TMenuItem; N5: TMenuItem; N6: TMenuItem; N7: TMenuItem; N8: TMenuItem; N9: TMenuItem; Edit1: TEdit; Label1: TLabel; N10: TMenuItem; N11: TMenuItem; N12: TMenuItem; N13: TMenuItem; procedure N4Click(Sender: TObject); procedure N5Click(Sender: TObject); procedure N6Click(Sender: TObject); procedure N11Click(Sender: TObject); procedure N12Click(Sender: TObject); procedure N13Click(Sender: TObject); procedure N8Click(Sender: TObject); procedure N9Click(Sender: TObject); procedure N7Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.N4Click(Sender: TObject); begin IBTable1.Active:= false; IBQuery1.Active:=false; IBQuery1.SQL.Clear; IBQuery1.SQL.Append('select * from stud order by forma, grup, fio'); IBQuery1.Active:=true; DataSource1.DataSet:=IBQuery1; end; procedure TForm1.N5Click(Sender: TObject); begin IBTable1.Active:= false; IBQuery1.Active:=false; IBQuery1.SQL.Clear; IBQuery1.SQL.Append('select * from stud '); IBQuery1.SQL.Append(' where grup = ''' +Edit1.Text+''''); IBQuery1.SQL.Append(' order by forma, grup, fio'); IBQuery1.Active:=true; DataSource1.DataSet:=IBQuery1; end; procedure TForm1.N6Click(Sender: TObject); begin IBTable1.Active:= false; IBQuery1.Active:=false; IBQuery1.SQL.Clear; IBQuery1.SQL.Append('select forma, grup, stud.fio, nazvan, ocenka, datekz '); IBQuery1.SQL.Append('from stud, predmet, sess '); IBQuery1.SQL.Append('where (stud.kodstud= sess.kodstud) '); IBQuery1.SQL.Append('and (predmet.kodpredm = sess.kodpredm) '); IBQuery1.SQL.Append('order by forma, grup, stud.fio '); IBQuery1.Active:=true; DataSource1.DataSet:=IBQuery1; end; procedure TForm1.N11Click(Sender: TObject); begin IBTable1.Active:= false; IBQuery1.Active:=false; IBQuery1.SQL.Clear; IBQuery1.SQL.Append('select stud.fio, grup, nazvan, forma, ocenka, datekz '); IBQuery1.SQL.Append('from stud, predmet, sess '); IBQuery1.SQL.Append('where (stud.kodstud= sess.kodstud) '); IBQuery1.SQL.Append('and (predmet.kodpredm = sess.kodpredm) '); IBQuery1.SQL.Append('group by forma, nazvan, grup, stud.fio, ocenka, datekz '); IBQuery1.SQL.Append('order by stud.fio, datekz '); IBQuery1.Active:=true; DataSource1.DataSet:=IBQuery1; end; procedure TForm1.N12Click(Sender: TObject); begin IBTable1.Active:= false; IBQuery1.Active:=false; IBQuery1.SQL.Clear; IBQuery1.SQL.Append('select sess.kodpredm, nazvan as "Предмет", '); IBQuery1.SQL.Append('max(ocenka) as "Макс.оценка",min(ocenka) as "Мин.оценка" '); IBQuery1.SQL.Append('from sess, predmet '); IBQuery1.SQL.Append('where predmet.kodpredm = sess.kodpredm '); IBQuery1.SQL.Append('group by sess.kodpredm, nazvan '); IBQuery1.Active:=true; DataSource1.DataSet:=IBQuery1; end; procedure TForm1.N13Click(Sender: TObject); begin IBTable1.Active:= false; IBQuery1.Active:=false; IBQuery1.SQL.Clear; IBQuery1.SQL.Append('select datekz as "Дата экзамена", '); IBQuery1.SQL.Append('max(stud.kurs) as "Самый старший курс в этот день" '); IBQuery1.SQL.Append('from sess, stud '); IBQuery1.SQL.Append('where (stud.kodstud = sess.kodstud) '); IBQuery1.SQL.Append('group by datekz order by datekz '); IBQuery1.Active:=true; DataSource1.DataSet:=IBQuery1; end; procedure TForm1.N8Click(Sender: TObject); begin IBTable1.Active:=false; IBTable1.TableName:='PREDMET'; IBTable1.IndexFieldNames:='KODPREDM'; DataSource1.DataSet:= IBTable1; IBTable1.Active:=true; end; procedure TForm1.N9Click(Sender: TObject); begin IBTable1.Active:=false; IBTable1.TableName:='PREDMET'; IBTable1.IndexFieldNames:='NAZVAN'; DataSource1.DataSet:= IBTable1; IBTable1.Active:=true; end; procedure TForm1.N7Click(Sender: TObject); begin IBTable1.Active:= false; IBQuery1.Active:=false; IBQuery1.SQL.Clear; IBQuery1.SQL.Append('select stud.fio, nazvan, ocenka, datekz '); IBQuery1.SQL.Append('from stud, predmet, sess '); IBQuery1.SQL.Append('where (stud.kodstud= sess.kodstud) '); IBQuery1.SQL.Append('and (predmet.kodpredm = sess.kodpredm) '); IBQuery1.SQL.Append('order by nazvan, stud.fio '); IBQuery1.Active:=true; DataSource1.DataSet:=IBQuery1; end; end.Скачать все файлы делфи-проекта и файл БД - STUDENTS.GDB