create table klienci
( klientid int unsigned not null auto_increment primary key,
nazwisko char(50) not null,
adres char(100) not null,
miejscowosc char(30) not null
);
create table zamowienia
(
zamowienieid int usnigned not null auto_increment primary key,
klientid int unsigned not null,
wartosc float(6,2),
data date not null
);
create table ksiazki
(
isbn char(13) not null primary key,
autor char(50),
tytul char(100),
cena float(4,2)
);
create table pozycje_zamowione
(
zamowieniaid int unsigned not null,
isbn char(13) not null,
ilosc tinyint unsigned,
primary key(zamowienieid, isbn)
);
create table recenzje_ksiazek
(
isbn char(13) not null primary key,
recenzja text
);
gdy wpisuje w konsoli:
mysql -u ksiazkorama -D ksiazki -p < c:\mysql\bin\ksiazkorama.sql
w celu dodania tabel do bazy to pojawia się błąd
1050(42S01) at line 2: Table ‘klienci’ already exists. czyli już istnieje takowa.
ale gdy daję komendę: show tables; to pokazuje że jest tylko jedna tabela ‘klienci’ a pozostałych w ogóle nie wczytało.
po zmienieniu tych fragmentów pojawia się taki błąd teraz:
ERROR 1064(42000) at line 12: You have an error in your SQL syntaxl check the maunal that corresponds to your MySQL server version for the right syntax to use near ‘unsigned not null auto_increment primary key, klientid int unsigned not null,wa’ at line 3.
drop table if exists `klienci`;
create table if not exists `klienci`
( klientid int unsigned not null auto_increment primary key,
nazwisko char(50) not null,
adres char(100) not null,
miejscowosc char(30) not null
);
drop table if exists `zamowienia`;
create table if not exists `zamowienia`
(
`zamowienieid` int unsigned not null auto_increment ,
`klientid` int unsigned not null ,
`wartosc` float( 6, 2 ) not null ,
`data` date not null ,
primary key ( `zamowienieid` )
);
drop table if exists `ksiazki`;
create table if not exists `ksiazki`
(
`isbn` char(13) not null,
`autor` char(50),
`tytul` char(100),
`cena` float(4,2),
primary key (`isbn`)
);
drop table if exists `pozycje_zamowione`;
create table if not exists `pozycje_zamowione`
(
`zamowienieid` int unsigned not null,
`isbn` char(13) not null,
`ilosc` tinyint unsigned,
primary key(zamowienieid, isbn)
);
drop table if exists `recenzje_ksiazek`;
create table if not exists `recenzje_ksiazek`
(
`isbn` char(13) not null,
`recenzja` text,
primary key (`isbn`)
);
CREATE TABLE jest OK, pod warunkiem, że masz pewność, iż dana tablica nie występuje już w Twojej bazie.
DROP TABLE IF EXISTS ...; CREATE TABLE IF NOT EXISTS ... spowodowało kolejno wymazanie danych tablic w razie gdy już istniały i wpisanie ich na nowo, a w razie gdy nie istniały były od razy wpisywana tak jak przy zwykłym CREATE TABLE. Ja zastosowałem tę metodę w celu wymazania w Twojej bazie potencjalnych błędów i zgłaszania przez SQL kolejnych ostrzeżeń.