第六週 課後實踐案例 出現 Incorrect string value: '\xC0\xD6\xC6\xF7' for column 'tName' at row 1

在這裏插入圖片描述
這裏的話在最下面括號外加charset = 'utf-8’


出現錯誤:Incorrect string value: ‘\xC0\xD6\xC6\xF7’ for column ‘tName’ at row 1
將數據庫編碼格式改爲utf-8
alter table 表名稱 convert to character set utf8;

————————————————————————————————————————

課後實踐習題
在這裏插入圖片描述
在這裏插入圖片描述
對應解答:

.
create database OnlineDB;.
(會員信息表)
create table Users(
    uID int(4) primary key auto_increment not null comment "會員ID",
    uName varchar(30) not null comment "用戶名",
    uPwd varchar(30) not null comment "密碼",
    uSex varchar(2) default "男" comment "性別",
    uBirth datetime(6) comment "出生日期",
    uPhone varchar(20) comment "電話",
    uEmail varchar(50) comment "電子郵箱",
    uQQ varchar(20) comment "QQ號碼",
    ulmage varchar(100) comment "用戶頭像",
    uCredit int(4) default 0 comment "積分",
    uRegTime datetime(6) comment "註冊時間")charset='utf8';
 
(商品類別表)
create table GoodsType(
    tID int(4) primary key auto_increment not null comment "類別ID",
    tName varchar(100) not null comment "類別名稱");

(商品信息表)
create table Goods(
    gdID int(4) primary key auto_increment not null comment "商品ID",
    tID int(4) not null comment "類別ID",
    gdCode varchar(50) not null comment "商品編號",
    gdName varchar(100) not null comment "商品名稱",
    gdPrice float(8) default 0 comment "價格",
    gdQuantity int(4) default 0 comment "庫存數量",
    gdSaleQty int(4) default 0 comment "已賣數量",
    gdCity varchar(50) default "長沙" comment "發貨地",
    gdImage varchar(100) comment "商品圖像",
    gdInfo text(16) comment "商品描述",
    gdAddTime datetime(6) comment "上架時間",
    gdHot int(4) default 0 comment "是否熱銷")charset='utf8';

(購物車信息表)
create table Scars(
   ScID int(4) primary key auto_increment not null comment "購物車ID",
   uID int(4) not null comment "用戶ID",
   gdID int(4) not null comment "商品ID",
   ScNum int(4) default 0 comment "購買數量");

(訂單信息表)
create table Orders(
  oID int(4) primary key auto_increment not null comment "訂單ID",
  uID int(4) not null comment "用戶ID",
  oTime datetime(6) not null comment "下單時間",
  oTotal float(8) not null default 0 comment "訂單金額");

(訂單詳細表)
create table OrderDetail(
  odID int(4) primary key auto_increment not null comment "詳情ID",
  oID int(4) not null comment "訂單ID",
  gdID int(4) not null comment "商品ID",
  odNum int(4) default 0 comment "購買數量",
  dEvalution varchar(8000) comment "商品評價",
  odTime datetime(6) comment "評價時間");.
添加外鍵約束   中的是的外鍵
alter table Goods add constraint fk_tID foreign key(tID) references GoodsType(tID);  //Goods中的tID是GoodsType 的外鍵
alter table Scars add constraint fk_uID foreign key(uID) references Users(uID);      //Scars中的uID是Users的外鍵
alter table Scars add constraint fk_gdID foreign key(gdID) references Goods(gdID);   //Scars中的gdID是Goods的外鍵
alter table Orders add constraint fk_sec_uID foreign key(uID) references Users(uID); //Orders中的uID是Users的外鍵
alter table OrderDetail add constraint fk_oID foreign key(oID) references Orders(oID);  //OrderDetail中的oID是Orders的外鍵
alter table OrderDetail add constraint fk_sec_gdID foreign key(gdID) references Goods(gdID); //OrderDetail中的gdID是Goods的外鍵
添加唯一性約束
alter table Users add unique(uName);  //Users中的uName
alter table Goods add unique(gdName); //Goods中的gdName
添加默認值約束
alter table Goods add gdAddTime datetime(6) default getdate();   ?????獲取默認值系統時間
alter table Goods add gdSaleQty int(4) default 0;   //這個是已經有默認值的了.
insert into GoodsType set tName = "樂器";  //在goodstype中加入新類名稱"樂器".
insert into Goods set tID = 1,gdCode="099",gdName = "紫竹洞簫",gdPrice = "288" ,gdQuantity = 10, gdCity = "浙江";.
update Goods set gdQuantity = 5 where gdCode="099";  //更改記錄是gdCode=099中的數量爲5.
delete from Goods where gdName="紫竹洞簫";

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章