嘿,所以我试图向我的数据库添加支票。我目前正在创建一个用于租车的MySQL数据库(这是一个用于大学的项目),我的约束是,只有他们有驾驶员编号的情况下,该人才是批准的客户,所以...
CREATE TABLE customers (
customer_id int(50) UNSIGNED ZEROFILL NOT NULL,
fname varchar(20) NOT NULL,
lname varchar(20) NOT NULL,
address varchar(30) NOT NULL,
city varchar(20) NOT NULL,
county ENUM('Armagh','Carlow','Cavan','Clare','Cork','Derry','Donegal','Down','Dublin','Fermanagh','Galway','Kerry','Kildare','Kilkenny','Laois','Leitrim','Limerick','Longford','Louth','Mayo','Meath','Monaghan','Offaly','Roscommon','Sligo','Tipperary','Tyrone','Waterford','Westmeath','Wexford','Wicklow') NOT NULL,
phone int(10) NOT NULL,
email varchar(20) NOT NULL,
payment_method ENUM ('Visa', 'Amex', 'Cash', 'American Express', 'Mastercard') NOT NULL,
status ENUM('Approved','Unapproved'),
driver_no int(10) NOT NULL,
PRIMARY KEY (customer_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
支票就像...?
检查driver_no当前吗?
该命令用于查看是否存在某些内容。他们必须有司机号码才能租车。
答案 0 :(得分:0)
DROP TABLE IF EXISTS customer;
CREATE TABLE customer
(customer_id SERIAL PRIMARY KEY
,firstname VARCHAR(12) NOT NULL
,licence_no VARCHAR(30) NULL
);
INSERT INTO customer VALUES
(1,'John',NULL),
(2,'Paul','LMW281F'),
(3,'George',NULL),
(4,'Ringo','STAR123');
DROP TABLE IF EXISTS rentals;
CREATE TABLE rentals
(rental_id SERIAL PRIMARY KEY,customer_id INT NOT NULL);
INSERT INTO rentals
SELECT NULL, customer_id FROM customer WHERE firstname = 'John' AND licence_no IS NOT NULL;
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
SELECT * FROM rentals;
Empty set (0.00 sec)