0
CREATE TABLE Customer (
customerid varchar(10) NOT NULL,
FirstName varchar(20) NOT NULL,
LastName varchar(20) NOT NULL,
StreetAddress varchar (30) NOT NULL,
City varchar (20)NOT NULL,
State varchar (20) NOT NULL,
Zip int(5) NOT NULL,
Hphone int (10) NOT NULL,
Mphone int (10) NOT NULL,
Ophone int (10) NOT NULL,
PRIMARY KEY (customerid));
CREATE TABLE OrderTable (
donutorderid varchar(10) NOT NULL,
customerid varchar (10) NOT NULL,
oderdate datetime (6) NOT NULL,
PRIMARY KEY (donutorderid)
);
CREATE TABLE Donut (
donutid varchar(10),
donutname varchar(20),
description varchar(30),
unitprice numeric,
PRIMARY KEY (donutid)
);
CREATE TABLE OrderLine (
donutorderid varchar (30),
donutid varchar (30),
qty int (10),
PRIMARY KEY (donutorderid,donutid)
);
ALTER TABLE OrderTable ADD INDEX checks (customerid),
ADD CONSTRAINT checks FOREIGN KEY (customerid) REFERENCES Customer (customerid);
ALTER TABLE OrderLine ADD INDEX has (donutorderid),
ADD CONSTRAINT has FOREIGN KEY (donutorderid) REFERENCES OrderTable (donutorderid);
ALTER TABLE OrderLine ADD INDEX available_in (donutid),
ADD CONSTRAINT available_in FOREIGN KEY (donutid) REFERENCES Donut (donutid);
create view CustInfo
AS Select customerid, concat(FirstName,LastName) as FullName from customer;
insert into customer
(customerid, FirstName, LastName, StreetAddress,
City, State, Zip, Hphone, Mphone, Ophone)
values ('123','John','Doe', 'one hoover lane', 'las vegas',
'nevada', 89104, 702555122, 702441111, 702332222);
數據截斷:暫時爲列「Hphone」範圍值中的第1行數據截斷誤差和int數據類型
當我有9位數字在我的電話例如702551212 vs 7025551212它的工作原理和Hphone,Mphone,Ophone都有int(10)。
請,*請*,格式化這個職位! –
另外 - 不要使用整數來存儲電話號碼。僅僅因爲它們包含數字不會使它們成爲數字(提示 - 不是0的數字通常不以「0」開頭)。使用varchar數據類型來代替... –
郵政編碼不是最好的數字存儲爲 – RiggsFolly