MySQL 命令行基本语法

CREATE TABLE `tb_emp` (
  `id` int(11) NOT NULL,
  `loc` varchar(60) DEFAULT NULL,
  `deptId` int(11) DEFAULT NULL,
  `salary` float DEFAULT NULL,
  PRIMARY KEY (`id`)
) ;

1. create database test_db; (create database if not exists test_db)// 创建数据库
2. show databases ; // 显示所有数据
3. use test_db; // 指定使用数据库
4. create table tb_emp (...); (create table if no exists tb_emp (...);)// 在指定的数据库建表
5. show tables; // 显示指定数据所有表
6.desc tb_emp; (describe tb_emp) // 查看指定表的结构
7.show create table tb_emp; // 查看建表的语句
8.alter table tb_emp rename tb_emp1; // 修改数据库表名
9.alter table tb_emp modify id varchar(30); // 修改数据库表字段类型
10. alter table tb_emp change name empName varchar(25); // 修改字段名称
11. alter table tb_emp add managerId int(10);  (alter table tb_emp add managerId int(10) not null; // 不能为空) ;//  添加字段
12.alter table tb_emp add num int(10) first not null; // 在表的第一列添加字段
13.alter table tb_emp drop num; // 删除表中的字段名
14.alter table tb_emp modify deptId int(11) first; // 修改字段为表中的第一个字段
15.alter table tb_emp modify deptId int(11) after id; // 修改某个字段到指定的字段之后
16.show engines; // 查看数据支持的存储引擎
17.show create table tb_emp; // 查看当前的存储引擎(ENGINE=InnoDB)
18.alter table tb_emp engine=MyISAM; // 更改表的存储引擎
19.alter table tb_emp drop primary key; // 删除主键
20.alter table tb_emp add primary key (id); // 添加主键
21.drop table if exists tb_emp; //  删除数据表
22.drop databases if exists test_db; // 删除数据库

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值