标签:odi 总结 nbsp uniq _id 排列 drop 增删改 查找
以上为老师总结:
#1 操作文件夹(库)
增
create database db1 charset utf8;
查
show databases;
show create database db1;
改
alter database db1 charset gbk;
删
drop database db1;
#2 操作文件(表)
切换到文件夹下:use db1
增
create table t1(id int,name char(10))engine=innodb;
create table t2(id int,name char(10))engine=innodb default charset utf8;
查
show tables;
show create table t1;
desc t1;#查看表结构
改
alter table t1 add age int;
alter table t1 modify name char(12);
删
drop table t1;
#3 操作文件的一行行内容(记录)
增
insert into db1.t1 values(1,‘egon1‘),(2,‘egon2‘),(3,‘egon3‘);
insert into db1.t1(name) values(‘egon1‘),(‘egon2‘),(‘egon3‘);
查
select * from t1;
select name from t1;
select name,id from t1;
改
update t1 set name=‘SB‘ where id=4;
update t1 set name=‘SB‘ where name=‘alex‘;
删
delete from t1 where id=4;
#对于清空表记录有两种方式,但是推荐后者
delete from t1;
truncate t1; #当数据量比较大的情况下,使用这种方式,删除速度快
#自增id
create table t5(id int primary key auto_increment,name char(10));
create table t4(id int not null unique,name char(10));
create table t5(id int primary key auto_increment
insert into t5(name) values
(‘egon5‘),
(‘egon6‘),
(‘egon7‘),
(‘egon8‘),
(‘egon9‘),
(‘egon10‘),
(‘egon11‘),
(‘egon12‘),
(‘egon13‘);
#拷贝表结构
create table t7 select * from t5 where 1=2;
alter table t7 modify id int primary key auto_increment;
insert into t7(name) values
(‘egon1‘),
(‘egon2‘),
(‘egon3‘),
(‘egon4‘),
(‘egon5‘),
(‘egon6‘),
(‘egon7‘),
(‘egon8‘),
(‘egon9‘),
(‘egon10‘),
(‘egon11‘),
(‘egon12‘),
(‘egon13‘);
delete from t7 where id=1; #删记录
update t7 set name=‘‘; #修改字段对应的值
------------------------------------------------
自己总结
文件的增删改查
1,增
create table t1(id int,name char(10));
2,改
alter table t1 charset utf8
3,查
show create table t1;
4,删除
drop table t1;
字段,段落,记录的增删改查
1,增
insert into t1 values(id int,name char())
2改:
update t1 set name=‘ ‘ where id=‘‘
update t1 set name =‘sb‘ where name=‘alex‘
3:查
selesct * from t1
selesct name from t1
selesct name,id from t1
4删:
delete from t1 where id=4 #这里一删就是删除一整行内容,会连着这一行的内容全部删除,
删除id 1后面的内容只会从id2开始加,不会重新再有id1.
truncate t1 #这里一删除就直接删除全部文件内容,不会有遗留,
自增ID
create table t1(id int primary key auto_increment,name char(10));
create table t1(id int primary key auto_increment,name char(10));
auto_increment
查找id 的条件语句
select * from t1 where id>5 and id<10;
创建一个t2 ,让t1表里面所有的东西传给t2
create table t2 select * from t1;
创建一个表t2,只要t1表的结构
create table t2 select * from t1 where 1=2;
更改表的结构
alter table t2 modify id int primary key auto_increment
正常排序
mysql> select t_id,t_name from test order by t_id;
让数据按照id排列
mysql> select t_id,t_name from test order by t_id desc;
让数据按照id倒序排列.
标签:odi 总结 nbsp uniq _id 排列 drop 增删改 查找
原文地址:http://www.cnblogs.com/52forjie/p/7482157.html