標籤:
安裝後登陸 -->mysql -uroot -p123456
顯示所有資料庫-->show databases;
建立新的資料庫-->create database 資料庫名;
刪除資料庫-->drop database 資料庫名;
使用資料庫-->use datsbase 資料庫名;
建立表 -->create table 表名( []內容可寫可不寫
-->欄位1 類型[約束],
-->欄位2 類型[約束]
-->foreign (主表外鍵欄位) references 從表名(從表主鍵欄位)
-->);
查看錶結構-->desc 表名;
顯示所有表-->show tables;
刪除表-->drop table 表名;
操作資料增加-->insert into 表名[指定欄位名] value(欄位);
刪除-->delete from 表名[條件陳述式]
修改-->update 表名 set 欄位1=值,欄位2=值;
修改表結構增加一列-->alter table 表名 add 欄位 類型;
刪除一列-->alter table 表名 drop 欄位名;
修改列名-->alter table 表名 change 舊欄位 新欄位 新欄位類型;
修改表名-->alter table 表名 rename 新表名;
更改約束-->alter table 表名 modify 欄位 約束 類型;
約束條件主鍵-->alter table 表名 modify 欄位 primary key;【方法一】
-->create table score(【方法二】
-->id int primary key,
-->score int not null
-->);
-->create table score(
-->id int primary key,
-->score int not null,
-->primary key(id) 【方法三】
-->);
外鍵-->alter table 表名 modify 欄位 foreign key 從表名(主鍵);【方法一】
-->create table stu(
-->id int primary key auto_increment,
-->xuehao_id int not null,
-->name varchar(10) unique,
-->sex enum(‘男‘,‘女‘) default‘男‘,
-->foreign key(xuehao_id) references score(id)【方法二】
-->);
非空-->not null;
預設-->default‘‘;
枚舉-->enum(‘‘,‘‘);
唯一-->unique(資料唯一,null除外);
自增-->auto_increment;
mysql 常用操作一