mysql基本操作--数据库表SQL操作

2)MySQL中表的相关操作?(DDL)
a)创建表(语法? create table)

1 create table if not exists pet(
2 id int primary key auto_increment,
3 name varchar(100) not null
4 );

当需要了解具体类型时可以:?具体数据类型
例如:?int
当需要查看某张表的创建语句时,可以使用
 1 show create table pet 
当需要显示表结构时可以使用:
 1 desc pet 
b)修改表(语法?alter table);不作为重点,自己了解
c)删除表(语法?drop table)
 1 drop table if exists pet; 

3)MySQL表中数据的操作?(DML)
1)向表中写入数据(insert)

1 insert into pet values (null,'A');
2 insert into pet(id,name) values (null,'B');
3 insert into pet(name)values('C');
4 insert into pet(name)values('D'),('E');

2)查询表中数据(select)

1 select * from pet;
2 select id,name from pet;
3 select id,name from pet where id=10;

分页查询:limit 语句的应用(语法参考?select)

1 select * from pet limit 2; --2为row_count(表示要取几条数据)
2 select * from pet limit 4,2; --4表示offset,2表示 row_count
3 select * from pet limit 2 offset 4;

猜你喜欢

转载自www.cnblogs.com/jayson-0425/p/10025612.html