关于mysql:mysql表的操作

7次阅读

共计 762 个字符,预计需要花费 2 分钟才能阅读完成。

创立表

create table 表名 (列名 1 数据类型,列名 2 数据类型) engine=innodb default charset=utf8;

实例:

#创立表 t1,id 列为 int 类型,不能为空。且自增;name 列为 char 类型,不超过 10 个字符

create table t1(id int not null auto_increment primary key,name char(10));

查看表的构造

desc 表名;

向表中增加内容 (增)

insert into 表名 (列名 1,列名 2) values(‘ 内容 1 ’,’ 内容 2 ’) ;

删除表

drop table 表名;

删除内容(删)

delete from 表名 where 条件;

实例:

#删除表 t1 中 id 小于 6 的

delete from t1 where id<6;

清空表

#如果表中有自增,清空表之后,从新创立新表时,自增数据会接着之前的

delete from 表名;
装置 mysql:http://shujuku.cuohei.com/
#如果表中有自增,清空表之后,从新创立新表时,自增数据不会接着之前的

truncate table 表名;

批改表中内容(改)

updata 表名 set 条件 where 条件;

实例:# 把表 t1 中年龄为 17 的改为 18

updata t1 set age=18 where age=17;

查看表的内容(查)

#查问所有列

select * from 表名;

#查问指定列

select 列 1,列 2 from 表名;

as 关键字

应用 as 给字段起别名

select id as 序号,name as 名字 from 表名;

正文完
 0