MySQL数据库&数据表之创建与删除
MySQL数据库与数据表的创建与删除
MySQL数据库的操作
- 创建数据库: create database db_game
- 如果数据库已经存在则需要先判断数据库是否存在,如果数据库不存在则创建: create database if not exists db_game
- 删除数据库: drop database db_game
- 查看数据库: show databases
MySQL数据表的操作
创建表
- 创建表: create table tb_user
- 创建表时添加数据: create table tb_user(id int(10),name varchar(10),password varchar(20))
- 查看表结构: desc tb_user
- 查看表: show table tb_user
- 查看某数据库中全部的表: show tables
- 删除表: drop table tb_user
修改表
- 添加一个字段: alter table tb_user add age int(5)
- 删除一个字段: alter table tb_user drop age
- modify&change
- modify: 修改某一个字段,修改字段属性,但是字段名称不变
- change: 改变某个字段,改变某个字段名称
- alter table tb_user change name account varchar(20)