一.创建员工表以及修改练习
mysql> create database myee_2204;
Query OK, 1 row affected (0.01 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| ee_2204 |
| myee_2204 |
| mysql |
| performance_schema |
| test |
+--------------------+
6 rows in set (0.00 sec)
mysql> use myee_2204
Database changed
mysql> show tables;
Empty set (0.00 sec)
mysql> create table Employee(
-> id int,
-> name varchar(20),
-> gender varchar(2),
-> email varchar(10),
-> remark varchar(50)
-> );
Query OK, 0 rows affected (0.01 sec)
mysql> show tables ;
+---------------------+
| Tables_in_myee_2204 |
+---------------------+
| employee |
+---------------------+
1 row in set (0.00 sec)
mysql> desc employee;
+--------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| name | varchar(20) | YES | | NULL | |
| gender | varchar(2) | YES | | NULL | |
| email | varchar(10) | YES | | NULL | |
| remark | varchar(50) | YES | | NULL | |
+--------+-------------+------+-----+---------+-------+
5 rows in set (0.01 sec)
mysql> alter table employee add age int;
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> alter table employee modify email varchar(50) ;
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> alter table employee drop remark;
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> alter table employee change name usename varchar(20);
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc employee;
+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| usename | varchar(20) | YES | | NULL | |
| gender | varchar(2) | YES | | NULL | |
| email | varchar(50) | YES | | NULL | |
| age | int(11) | YES | | NULL | |
+---------+-------------+------+-----+---------+-------+
5 rows in set (0.01 sec)
二.mysql基础语法命令
1.插入
1)insert into 表名 values(值1,值2,值3,值4...,值n) ;-- 一次插入一条
2)insert into 表名 values (值1,值2,值3,值4...,值n),(值1,值2,值3,值4...,值n)....-- 一次插入多条
3)insert into 表名(字段名称1,字段名称2,,,) values(值1,值2....) ;
2.查询
查询表的记录 DQL语句 :数据库查询语句
查询全表 select *(所有字段) from 表名;(企业中 "禁止"使用*, 必须写全部字段!)
3.修改
1)update 表名 set 字段名称 = 值 where 字段名称 = xx ; -- 修改单个字段
2)update 表名 set 字段名称1 = 值1,字段名称2 = 值2,字段名称3= 值3,...,字段名称2 = 值 n where 字段名称 = xx ;-- 修改多个字段
3)update 表名 set 字段名称= 值;--批量修改,针对数量比较小的时候
update 表名 set 字段名称 = 值 where 条件1 =xx and 条件2 and 条件3.....