Buraya iki örnek koyuyorum.
daha sonra bunun nasıl işlediğini anlatacağım ama komutlar vs var içinde. Bu scripleri kullanarak bir veri tabanı oluşturup içini dolduruyoruz ki oynayabilelim.
drop database SofaAG;
create database SofaAG;
use SofaAG;
create table t_plattform (platt_nr integer,hersteller_nr integer, typ varchar(20), motor varchar(40),leistung_in_kw integer, hubraum integer, getriebe varchar(20), kabine varchar(20), lieferzeit_tage integer, verrechnungspreis float(10,2), primary key (platt_nr));
create table t_aufbau ( aufbau_nr integer, art varchar(20), hersteller_nr integer, typ varchar(20), lieferzeit_tage integer, verrechnungspreis float(10,2), primary key (aufbau_nr));
create table t_sonder (sonder_nr integer, bezeichnung varchar(20), hersteller_nr integer, typ varchar(20), lieferzeit_tage integer, verrechnungspreis float(10,2), primary key (sonder_nr));
create table t_bestellpos (bestell_nr integer, teil_nr integer, kennzeichen integer,menge integer,primary key (bestell_nr));
insert into t_plattform (platt_nr,hersteller_nr, typ,motor,leistung_in_kw,hubraum,getriebe, kabine,lieferzeit_tage,verrechnungspreis) values (1234,1147,"F 102","12-Zylinder-Diesel",500,36000,"12-Gang-Automatic","2-standard",30,62500.50);
insert into t_aufbau (aufbau_nr,art,hersteller_nr,typ,lieferzeit_tage,verrechnungspreis) values (238,"Autokran",8712,"K 21",40,105000.00);
insert into t_sonder (sonder_nr,bezeichnung, hersteller_nr, typ, lieferzeit_tage,verrechnungspreis) values (144,"Klimaanlage",3049,"Ktronic",20,3000.00);
insert into t_bestellpos (bestell_nr, teil_nr, kennzeichen,menge) values (3111,1234,1,1);
GrandHotel
drop database grandhotel;
create database grandhotel;
use grandhotel;
create table Zimmer ( zimmer_id integer, kategorie_id integer,primary key(zimmer_id));
create table Kategorie (kategorie_id integer auto_increment,kat_bezeichnung varchar(20),kat_preis_EZ float, kart_preis_DZ float, primary key (kategorie_id));
create table Gast (gast_id integer, g_name varchar(20),g_vorname varchar(20),g_strasse varchar(50),g_strasse_nummer integer, g_plz varchar(5), g_ort varchar(20), g_stammgast integer, primary key(gast_id));
create table Rechnung (rechnung_id integer,gast_id integer, zimmer_id integer, r_belegung varchar(10),r_ankuft date, r_abreise date, primary key(rechnung_id));
insert into Zimmer (Zimmer_id,kategorie_id) values ("101","1");
insert into Zimmer (Zimmer_id,kategorie_id) values ("102","1");
insert into Zimmer (Zimmer_id,kategorie_id) values ("103","1");
insert into Zimmer (Zimmer_id,kategorie_id) values ("104","2");
insert into Kategorie (kat_bezeichnung,kat_preis_EZ,kart_preis_DZ) values ("Standard","70","100");
insert into Kategorie (kat_bezeichnung,kat_preis_EZ,kart_preis_DZ) values ("Juniorsuite","80","120");
insert into Kategorie (kat_bezeichnung,kat_preis_EZ,kart_preis_DZ) values ("Suite","120","200");
insert into Kategorie (kat_bezeichnung,kat_preis_EZ,kart_preis_DZ) values ("Luxussuite","180","280");
insert into Gast (gast_id,g_name,g_vorname,g_strasse,g_strasse_nummer,g_plz,g_ort,g_stammgast) values ("4711","Meier","Hans","Hauptstr.","1","11111","Adorf","1");
insert into Gast (gast_id,g_name,g_vorname,g_strasse,g_strasse_nummer,g_plz,g_ort,g_stammgast) values ("4712","Schulze","Fritz","Mainweg","23","22222","Bhausen","0");
insert into Gast (gast_id,g_name,g_vorname,g_strasse,g_strasse_nummer,g_plz,g_ort,g_stammgast) values ("4713","Müller","Willi","Fuldaweg","5","33333","Ostadt","0");
Bu scripleri “SofaAG.sql” ve “grandhotel.sql” olarak kaydettikten sonra; mysql e girip boş birer db oluşturuyoruz.
MariaDB [(none)]> create database grandhotel;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> create database SofaAG;
Query OK, 1 row affected (0.00 sec)
sonra quit diyerek Mysqlden çıkıyoruz ve terminalden
mysql -uroot -proot SofaAG < SofaAG.sql
mysql -uroot -proot grandhotel < grandhotel.sql
Tekrar girip kontrol ediyoruz.
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| SofaAG |
| grandhotel |
| information_schema |
| mysql |
| performance_schema |
+--------------------+
5 rows in set (0.00 sec)
MariaDB [(none)]> use grandhotel;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [grandhotel]> show tables;
+----------------------+
| Tables_in_grandhotel |
+----------------------+
| Gast |
| Kategorie |
| Rechnung |
| Zimmer |
+----------------------+
4 rows in set (0.00 sec)
Ve bir table a kontrol için bakıyoruz.
MariaDB [grandhotel]> select * from Zimmer;
+-----------+--------------+
| zimmer_id | kategorie_id |
+-----------+--------------+
| 101 | 1 |
| 102 | 1 |
| 103 | 1 |
| 104 | 2 |
+-----------+--------------+
scriptimiz çalışmış. Artık oynayabiliriz 🙂