一:
展示数据库:mysql> show databases;
二:
创建数据库:create database company; 使用所创建的数据库:mysql> use company; 创建一个表,并添加各种约束:创建tb_worker: create table tb_worker( id int(11) primary key auto_increment, name varchar(30) not null, sex enum('w','m') default 'm', hobby set('football','basketball','volleyball'), score float(3,1) unsigned, mobile char(11) unique not null, entry_time date )engine=myisam; mysql>desc tb_worker; desc table 表示的创建好的表的描述,字段名称,类型,是否为主键等,以表格的形式存在
三:
mysql> alter table tb_worker modify mobile varchar(11); 执行SQL 语句,讲mobile 字段的数据类型修改为 varchar(11) mysql> alter table tb_worker add intro text after mobile; 执行SQL 语句,在mobile 字段后面添加 intro 字段
四:
mysql> insert into tb_worker(id,name,sex,hobby,score,mobile,intro,entry_time) values(1,'小赵','m','basketball',9.2,13899991111,null,'2009-5-8'); 指定字段和值,插入一条记录,表名称后跟指定要插入的字段;value后跟指定在列表中要插入的数据; mysql> insert into tb_worker values(2,'小钱','m','basketball,volleyball',9.1,13899992222,null,'2008-6-8'); 不指定字段,只指定值,插入一条记录
五:
同时向表格中插入多条记录: mysql> insert into tb_worker -> values(3,'小孙','w','football',9.1,13899993333,null,'2015-9-2'), -> (4,'小李','m','basketball,football',9.2,13899994444,null,'2011-5-3'), -> (5,'小周','w','volleyball',9.0,13899995555,null,'2017-1-9'), -> (6,'小吴','m','football,volleyball',9.3,13899996666,null,'2014-7-7');
六:
mysql> update tb_worker set hobby='football' where name='小吴'; 修改name值为小吴的记录,将其hobby值修改为football : mysql> update tb_worker set score=score+0.5 where id<4; 将id值小于4的员工的score值加0.5 mysql> delete from tb_worker where sex='w'; 执行以下语句删除sex值为w的员工: mysql> select * from tb_worker; 查询结果