標籤:校正 values for http 字元集 字元 script ddr ima
1 show variables like ‘character_set_client‘;#查詢字元集 2 show databases;#列出所有的伺服器上的資料庫alter 3 create database if not exists test;#建立一個資料庫 4 drop database fk;#刪除資料庫 5 show tables from test;#顯示一個資料庫中的表 6 use test; 7 8 create table tb_dept( 9 Id int primary key auto_increment,#部門編號 整形 主鍵 自增長10 Name varchar(18),#部門名稱11 description varchar(100)#描述12 );13 14 show tables from test;15 16 desc tb_dept;#查看錶資訊17 18 show create table tb_dept;19 20 use test;21 #員工表22 create table tb_emp(23 id int primary key auto_increment,#auto_increment只是MySQL特有的24 Name varchar(18),25 sex varchar(2),26 age int,27 address varchar(200),28 email varchar(100)29 );30 31 drop table tb_dept;32 #修改列類型33 #注意:不是任何情況下都可以去修改的,34 #只有當欄位只包含空值時才可以修改。35 alter table tb_emp modify sex varchar(4);36 #增加列37 alter table tb_emp add tel varchar(12);38 #刪除列39 alter table tb_emp drop tel;40 alter table tb_emp drop column tel;41 #列改名42 alter table tb_emp change Name emp_Name varchar(18);43 #更改表名44 alter table tb_emp rename emp;45 rename table emp to tb_emp;46 47 insert into dept_emp (Name,sex,age,address,email)values(‘‘,‘‘,‘‘,‘‘,‘‘);48 49 #約束50 #是在表上強制執行地資料校正規則,主要用於保證資料庫地完整性51 /*52 not null 53 unique 唯一鍵tb_depttb_dept54 primary key 55 foreign key 外鍵56 check 檢查57 */58 59 create table tb_emp(60 id int primary key auto_increment,61 Name varchar(18),62 sex varchar(2) default‘男‘ check(sex=‘男‘or sex=‘女‘),#表級寫法check 在mysql中不起作用63 age int,64 address varchar(200),65 email varchar(100) unique,66 dept_id int,#references tb_dept(id) #表級寫法外鍵不起作用67 constraint foreign key fk_emp(dept_id) references tb_dept(id)68 );69 70 #建立表之後在添加71 alter table tb_emp add constraint foreign key fk_emp(dept_id) references tb_dept(id);
MySQL建立表的語句