对不起我的愚蠢问题,但是当我完成MySQL时,我很高兴。不幸的是,当我正确修复一个错误时,我在数据库中发现了很多错误,因此我又遇到了另一个错误。另外,这是我的数据库,那个家伙现在真的很无聊,请为他们写我的bug和解决方案。我是程序员的新手,这个数据库我大约要花4天的时间!

CREATE TABLE`Skoleni` (
    `sk_id` INT NOT NULL UNIQUE AUTO_INCREMENT,
    `Cena` MEDIUMINT NOT NULL,
    `Obsazenost` text NOT NULL,
    `Kapacita` datetime NOT NULL,
    `Popis` text,
    `Prerekvizity` text,
    `Certifikat` MEDIUMINT NOT NULL,
    PRIMARY KEY (`sk_id`),
    FOREIGN KEY (`sk_id`) REFERENCES Skoleni_has_Termin(`Skoleni_sk_id`),
    FOREIGN KEY (`sk_id`) REFERENCES Skoleni_has_Uzivatel(`Skoleni_sk_id`)
);

CREATE TABLE `Skoleni_has_Termin`(
    `Skoleni_sk_id`INT NOT NULL UNIQUE,
    `Termin_ter_id` INT NOT NULL UNIQUE,
    PRIMARY KEY (`Skoleni_sk_id`)
);

CREATE TABLE `Termin` (
    `ter_id` INT NOT NULL UNIQUE AUTO_INCREMENT,
    `Datum_cas` DATETIME NOT NULL,
    `Misto_mo_id` INT NOT NULL,
    PRIMARY KEY (`ter_id`),
    FOREIGN KEY (`ter_id`) REFERENCES Skoleni_has_Termin(`Termin_ter_id`)
);

CREATE TABLE `Misto` (
    `mo_id` INT NOT NULL UNIQUE AUTO_INCREMENT,
    `ulice` MEDIUMINT NOT NULL,
    `cislo_popisne` MEDIUMINT NOT NULL,
    `lat` FLOAT (10,6) NOT NULL,
    `lng` FLOAT (10,6) NOT NULL,
  PRIMARY KEY (`mo_id`)
)ENGINE = MYISAM;

SELECT TABLE.Misto(
INSERT (`ulice`, `cislo_popisne`, `lat`, `lng`),
VALUES (`dr_Zikmunda_Wintra_376_5``16000 Praha 6 Bubenec``14.407438``50.101049`)
);

CREATE TABLE `Skoleni_has_Uzivatel` (
    `Skoleni_sk_id` INT NOT NULL UNIQUE,
    `Uzivatel_uziv_id` INT NOT NULL UNIQUE,
    PRIMARY KEY (`Skoleni_sk_id`)
);

CREATE TABLE `Uzivatel` (
    `uziv_id` INT NOT NULL UNIQUE AUTO_INCREMENT,
    `Jmeno` VARCHAR(30) NOT NULL,
    `Typ` MEDIUMINT UNIQUE,
    `Heslo` VARCHAR(32) NOT NULL,
    `Potvrzeni` VARCHAR(1) NOT NULL,
   PRIMARY KEY (`uziv_id`),
   FOREIGN KEY (`uziv_id`) REFERENCES Skoleni_has_Uzivatel(`Uzivatel_uziv_id`)
);

CREATE TABLE `Skoleni_has_Lektor` (
    `Skoleni_sk_id` INT NOT NULL UNIQUE,
    `Lektor_lek_id` INT NOT NULL UNIQUE,
    PRIMARY KEY (`Lektor_lek_id`)
);

CREATE TABLE `Lektor` (
    `lek_id` INT NOT NULL UNIQUE AUTO_INCREMENT,
    `Titul'pred'` VARCHAR(10) NOT NULL,
    `Jmeno` VARCHAR(20) NOT NULL,
    `Prijmeni` VARCHAR(20) NOT NULL,
    `Titul'za'` VARCHAR(10),
    `Firma` VARCHAR(30),
    `Rodne cislo` CHAR(11) NOT NULL,
    `Datum narozeni` DATE NOT NULL,
   PRIMARY KEY (`lek_id`)
);

CREATE TABLE `Firma` (
    `fir_id` INT NOT NULL UNIQUE AUTO_INCREMENT,
    `E-mail` VARCHAR(15) NOT NULL,
    `Telefon` VARCHAR(15) NOT NULL,
    `Web` VARCHAR(30),
    `IC` CHAR(8) NOT NULL,
    `DIC` VARCHAR(12) NOT NULL,
    `Misto_mo_id` INT NOT NULL,
   PRIMARY KEY (`fir_id`),
   PRIMARY KEY (`Misto_mo_id`),
   FOREIGN KEY (`Misto_mo_id`) REFERENCES Firma(`Misto_mo_id`)
);

最佳答案

表'skoleni_has_termin'和'skoleni_has_lektor'在这里很可能不需要。我会将日期带到培训表中,而在skoleni表中仅保留lektor_id,因为培训与讲师之间的关系是1:n而不是m:n(除非一项培训可以有一名以上讲师)

10-07 21:46