006_表的CRUD的操作
1. 創建表
1.1. 創建表命令:
create table `表名`(
`列名1` 列的類型(長度) 約束,
`列名2` 列的類型(長度) 約束,
...
) engine=數據庫引擎 auto_increment=自動遞增起始值 default charset=字符集; 。
1.2. engine數據庫引擎一般為InnoDB。
1.3. auto_increment自動遞增起始值一般為1。
1.4. default charset默認字符集一般為utf8。
1.6. 表名和列名需要加`符號。
1.7. 創建一個學生表
-- 學生id -- 姓名name -- 姓別sex -- 出生日期birthday -- 住址address -- 身高height -- 體重weight -- 說明introducecreate table `student` ( `id` bigint(20) not null auto_increment, `name` varchar(16) default null, `sex` char(2) default null, `birthday` datetime default null, `address` text, `height` float(16,2) default null, `weight` double(16,3) default null, `introduce` longtext, primary key (`id`) ) engine=InnoDB auto_increment=1 default charset=utf8;2. 查看表
2.1. 查看所有表命令: show tables; 。
2.2. 查看表結構命令: desc `表名`; 。
2.3. 查看創建表過程命令: show create table `表名`; 。
3. 修改表
3.1. 添加列命令: alter table `表名` add `列名` 列的類型 列的約束; 。
3.2. 修改列命令: alter table `表名` modify `列名` 列的類型 [null/not null | auto_increment | comment | zerofill]; 。
3.3. 修改列名命令: alter table `表名` change `舊列名` `新列名` 列的類型; 。
3.4. 刪除列命令: alter table `表名` drop `列名`; 。
3.5. 修改表名命令: rename table `舊表名` to `新表名`; 。
3.6. 修改表的字符集命令: alter table `表名` character set 字符集; 。
4. 刪除表
4.1. 刪除表命令: drop table `表名`; 。
總結
以上是生活随笔為你收集整理的006_表的CRUD的操作的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 005_MySQL数据类型
- 下一篇: 007_SQL约束