我正在学习MySQL,我正在尝试创建一个数据库和一些表。我在其中两张桌子上收到错误,但在我的生活中,我看不到我错过的内容。
抛出错误的两个表是: MAINTANANCE_REPAIR 和 TRIP。
如果有人能够发现我所缺少的东西,那将会非常有帮助。谢谢!
CREATE DATABASE IF NOT EXISTS CTSDB30091479;
use CTSDB30091479;
CREATE TABLE IF NOT EXISTS LANGUAGE(
LanguageCode CHAR(2) PRIMARY KEY,
LanguageName VARCHAR(50)
)
Engine=InnoDB;
CREATE TABLE IF NOT EXISTS COUNTRY(
CountryCode CHAR(2) PRIMARY KEY,
CountryName VARCHAR(50)
)
Engine=InnoDB;
CREATE TABLE IF NOT EXISTS COUNTRY_LANGUAGE(
CountryCode CHAR(2),
LanguageCode VARCHAR(50),
PRIMARY KEY(CountryCode, LanguageCode),
FOREIGN KEY(CountryCode) REFERENCES COUNTRY(CountryCode),
FOREIGN KEY(LanguageCode) REFERENCES LANGUAGE(LanguageCode)
)
Engine=InnoDB;
CREATE TABLE IF NOT EXISTS LOCATION_TYPE(
LocTypeID INT AUTO_INCREMENT PRIMARY KEY,
LocTypeDescription VARCHAR(40)
)
Engine=InnoDB;
CREATE TABLE IF NOT EXISTS LOCATION(
LocationID INT AUTO_INCREMENT PRIMARY KEY,
StreetNo VARCHAR(5),
StreetName VARCHAR(50),
City VARCHAR(30),
LocTypeID INT,
FOREIGN KEY(LocTypeID) REFERENCES LOCATION_TYPE(LocTypeID)
)
Engine=InnoDB;
CREATE TABLE IF NOT EXISTS DRIVER(
DriverLicenseNum VARCHAR(18) PRIMARY KEY,
DriverFirstName VARCHAR(20),
DriverLastName VARCHAR(20),
ClearenceLevel CHAR(1),
HasSecurity CHAR(1),
HasFirstAid CHAR(1),
IsAvailable CHAR(1)
)
Engine=InnoDB;
CREATE TABLE IF NOT EXISTS DRIVER_LANGUAGE(
LanguageCode CHAR(2),
DriverLicenseNum VARCHAR(18),
PRIMARY KEY(LanguageCode, DriverLicenseNum),
FOREIGN KEY(LanguageCode) REFERENCES LANGUAGE(LanguageCode),
FOREIGN KEY(DriverLicenseNum) REFERENCES DRIVER(DriverLicenseNum)
)
Engine=InnoDB;
CREATE TABLE IF NOT EXISTS CERTIFYING_BODY(
CertBodyID INT AUTO_INCREMENT PRIMARY KEY,
CertBodyName VARCHAR(18)
)
Engine=InnoDB;
CREATE TABLE IF NOT EXISTS DRIVER_SECURITY(
DriverLicenseNum VARCHAR(18) PRIMARY KEY,
CertBodyID INT(50),
SecurityLevel CHAR(1),
CertDate DATE,
FOREIGN KEY (DriverLicenseNum) REFERENCES DRIVER(DriverLicenseNum),
FOREIGN KEY (CertBodyID) REFERENCES CERTIFYING_BODY(CertBodyID)
)
Engine=InnoDB;
CREATE TABLE IF NOT EXISTS DRIVER_FIRSTAID(
DriverLicenseNum VARCHAR(18) PRIMARY KEY,
FirstAidLevel CHAR(1),
FirstAidDate DATE,
FOREIGN KEY (DriverLicenseNum) REFERENCES DRIVER(DriverLicenseNum)
)
Engine=InnoDB;
CREATE TABLE IF NOT EXISTS VEHICLE(
VIN CHAR(17) PRIMARY KEY,
VEH_Make VARCHAR(30),
VEH_Model VARCHAR(30),
VEH_Colour VARCHAR(20),
VEH_RegoNum CHAR(6),
VEH_Odometer INT(6),
VEH_Availability CHAR(1),
VEH_SeatCapacity INT(2)
)
Engine=InnoDB;
CREATE TABLE IF NOT EXISTS MAINTANANCE_REPAIR(
VIN CHAR(17),
OdometerReading INT(6),
MR_Type CHAR(1),
MR_Date DATE,
MR_Cost DECIMAL,
MR_Details VARCHAR(100),
PRIMARY KEY(VIN, OdometerReading),
FOREIGN KEY(VIN) REFERENCES VEHICLE(VIN),
)
Engine=InnoDB;
CREATE TABLE IF NOT EXISTS OFFICIAL_ROLE(
RoleID INT AUTO_INCREMENT PRIMARY KEY,
RoleDescription VARCHAR(40)
)
Engine=InnoDB;
CREATE TABLE IF NOT EXISTS OFFICIAL(
OfficialID CHAR(8) PRIMARY KEY,
LanguageCode CHAR(2),
CountryCode CHAR(2),
OfficialFirstName VARCHAR(40),
OfficialLastName VARCHAR(40),
OfficialRole INT,
FOREIGN KEY (LanguageCode) REFERENCES LANGUAGE(LanguageCode),
FOREIGN KEY (CountryCode) REFERENCES COUNTRY(CountryCode),
FOREIGN KEY (OfficialRole) REFERENCES OFFICIAL_ROLE(RoleID)
)
Engine=InnoDB;
CREATE TABLE IF NOT EXISTS TRIP(
BookingRefNum INT AUTO_INCREMENT PRIMARY KEY,
VIN CHAR(17),
DriverLicenseNum CHAR(18),
OfficialID CHAR(8),
PickUpLocID INT,
DropOffLocID INT,
StartTimeIntended DATETIME,
EndTimeIntended DATETIME,
StartTimeActual DATETIME,
EndTimeActual DATETIME,
StartKM INT(6),
EndKM INT(6),
FOREIGN KEY (VIN) REFERENCES VEHICLE(VIN),
FOREIGN KEY (DriverLicenseNum) REFERENCES DRIVER(DriverLicenseNum),
FOREIGN KEY (OfficialID) REFERENCES OFFICIAL(OfficialID),
FOREIGN KEY (PickUpLocID) REFERENCES LOCATION(LocationID),
FOREIGN KEY (DropOffLocID) REFERENCES LOCATION(LocationID),
)
Engine=InnoDB;
答案 0 :(得分:2)
在两个表上,您在表定义的最后一行有一个额外的逗号:
Sub OpenSQL(ByRef conSQL)
Set conSQL = Server.CreateObject("ADODB.Connection")
conSQL.connectionTimeout = 60
ConSQL.CommandTimeout = 0
conSQL.Open "my driver / database"
End Sub
删除它,你会很高兴。