MySQL学习笔记

**创建表**:
use equipment;

create table ghes(
User varchar(20),
Equipment_category varchar(20),
Equipment_type varchar(20),
Start_up_time datetime(6),
Remarks varchar(50),
id int not null auto_increment,
primary key(id));

**向表中插入数据:**
insert into ghys(User,Equipment_category,Equipment_type,Start_up_time) values("王燕","兼容机","至强E3",
"2015-04-01")

**批量修改字段值:**
update ghys set Equipment_type = replace(Equipment_type,'至强E3','至强E3 1232')where id
<4;
**如何删除一条记录:**
delete from ghes where id=7;

**添加字段并赋值:**
alter table equipment.szfy add Usage_state varchar(10) default '正在使用';
alter table equipment.szfy add department varchar(10) default '市政分院' after id; 注:在某一字段前赋值

**多表查询:**
SELECT * FROM equipment.cwb UNION SELECT * FROM equipment.ghes UNION SELECT * FROM equipment.ghys UNION SELECT * FROM equipment.ghss UNION SELECT * FROM equipment.jszlb 
UNION SELECT * FROM equipment.jts UNION SELECT * FROM equipment.jyb UNION SELECT * FROM equipment.jzfy UNION SELECT * FROM equipment.rlzyb UNION SELECT * FROM equipment.szfy
UNION SELECT * FROM equipment.tdb UNION SELECT * FROM equipment.xxb UNION SELECT * FROM equipment.yld UNION SELECT * FROM equipment.zxb ORDER BY department;

你可能感兴趣的:(数据库)