免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費(fèi)電子書(shū)等14項(xiàng)超值服

開(kāi)通VIP
mysql中的表操作

------------恢復(fù)內(nèi)容開(kāi)始------------

創(chuàng)建數(shù)據(jù)庫(kù)

  create database 數(shù)據(jù)庫(kù)名

切換數(shù)據(jù)庫(kù)

  use 數(shù)據(jù)庫(kù)名

建表:

  create table 表名 (

    字段名1,類(lèi)型,約束

    字段名2,類(lèi)型,約束

    ...

  )

約束:

 1.主鍵約束

  1)直接在建表時(shí)字段類(lèi)型后加 primary key

  2)在表最后加 constraint 約束名 primary key(字段名)

  3)表外修改 alter table 表名 add constraint 約束名 primary key(字段名)

 2.檢查約束

  1)直接在建表類(lèi)型后加 check(約束條件)

  2)在表最后加 constraint 約束名 check(約束條件)

  3)表外修改 alter table 表名 add constraint 約束名 check(約束條件)

  注:mysql不支持檢查約束,但是寫(xiě)上檢查約束不會(huì)報(bào)錯(cuò)

 3.非空約束

  1)直接在創(chuàng)建表的類(lèi)型后加 not null

  2) 在表最后加入 constraint 約束名 check(字段名 is not null)

  3)在表外修改 alter table 表名 modify 字段名 字段類(lèi)型 not null

 4.唯一約束

  1)直接在創(chuàng)建表的類(lèi)型后加 unique

  2) 在表的最后加入 constraint 約束名 unqiue(字段名)

  3) 在表外修改 alter table 表名 add constraint 約束名 unique(字段名)

 5.外鍵約束

  1)直接在創(chuàng)建表的類(lèi)型后加 references 父表名(父表主鍵名)

  2)在表的最后加入 constraint 約束名 foreign key(字段名) references 父表名(父表主鍵名)

  3)在表外修改 alter table 表名 add constraint 約束名 foreign key(字段名) references 父表名(父表主鍵名)on delete set null on updata cascade

 6.默認(rèn)約束

  1)直接在創(chuàng)建表的類(lèi)型后加 default 默認(rèn)值

  2)在表外修改 alter table 表名 add constraint 約束名 

刪除約束

  alter table 表名 drop constraint 約束名

 

表的修改

  1)添加字段

    alter table 表名 add 字段名 字段類(lèi)型 注:在表中已經(jīng)有值時(shí),不能加非空約束

  2)刪除字段

    alter table 表名 drop 字段名

  3)修改字段類(lèi)型

    alter table 表名 modify 字段名 新字段類(lèi)型

  4)修改字段名

    alter table 表名 change 字段名 新字段名 字段類(lèi)型

  5)修改表名

    alter table 表名 rename as 新表名

  6)刪除表

    drop table 表名

 

 查看當(dāng)前數(shù)據(jù)庫(kù)中所有表

  show tables

本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶(hù)發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
Access sql語(yǔ)句創(chuàng)建表及字段類(lèi)型
SQL初級(jí)----創(chuàng)建表和約束
MySQL常用基本操作
SQL的主鍵和外鍵的作用
Mysql基礎(chǔ)02-約束
MySQL - DDL -常見(jiàn)約束
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服