mysql重新命名表,建立外來鍵,增 刪 改列名例項

2021-04-30 08:55:07 字數 1018 閱讀 9058

##mysql重新命名表,建立外來鍵,增、刪、改列名例項

##增加到某個字段之後

alter table tb_nippon_mms_info add province varchar(50) default null after retcode;

alter table tb_nippon_mms_info add city varchar(50) default null after province;

##增加到某個字段之前

alter table tb_nippon_mms_info add province varchar(50) default null before retcode;

alter table tb_nippon_mms_info add city varchar(50) default null before province;

##刪除名字為states的列

alter table tb_nine_integral_mo_info drop  column states ;

##改變手機號碼欄位為約束鍵

alter table business.tb_nine_ticket_popedom change phone  phone  varchar(50)  not null unique;

##改變列名flag為states

alter table tb_nine_integral_mo_info change flag  states tinyint(1);

–重新命名表

rename table t_softwareport to software_port;

–建立外來鍵

alter table software_port add constraint fk_software_port_softwareprocessid foreign key (softwareprocessid)

references software_process (id) on delete restrict on update restrict;

mysql 83重新命名表 MySQL命令

mysql 是乙個關係型資料庫,存在表的概念.結構,資料庫可以存放多張表,每個表裡可以存放多個字段,每個字段可以存放多個記錄.phpstudy使用終端開啟資料庫的命令列 密碼 root 資料庫檢視資料庫的指令 show databases 建立資料庫 create database name 刪除資...

mysql建立外來鍵

建立外來鍵的前提 本表的列必須與外來鍵型別相同 外來鍵必須是外表主鍵 外來鍵作用 使兩張表形成關聯,外來鍵只能引用外表中的列的值!指定主鍵關鍵字 foyunmkreign key 列名 引用外來鍵關鍵字 references 外來鍵表名 外來鍵列名 事件觸發限制 on delete和on updat...

mysql建立外來鍵案例 MySQL外來鍵例項

外來鍵例項 性別表create table gender gid int auto increment primary key not null,gender char 10 insert into gender gender values male female unknown 乙個表只能有乙個主...