常用数据库操作语句(2)

时间:2018-07-17 10:19:41   收藏:0   阅读:179
查看表结构
desc test;

显示表列定义
show columns from test;

显示表的索引
show index from test;

插入表数据
INSERT INTO book (
book_name,
bokk_author,
price,
publish_date
)
VALUES
("c#", "hhq", 40, NOW()),#可以指定多行的值
("编程语言", "hhq", 40, NOW())

查询表所有数据
select * from book;

查询指定列数据库
select id,book_name name from book;
select id,book_name 书名 from book;

SELECT
id,
book_name,
bokk_author
FROM
book t
WHERE
t.bokk_author = "hhq" and id!=2

SELECT
id,
book_name,
bokk_author
FROM
book t
WHERE
t.bokk_author = "hhq" order by id DESC

排序查找,使用limit
SELECT
id,
book_name,
bokk_author
FROM
book t
WHERE
t.bokk_author = "hhq" order by id DESC limit 2

SELECT
id,
book_name,
bokk_author
FROM
book t
WHERE
t.bokk_author = "hhq" order by id DESC limit 2,1#limit后面的1条,也就是查找第3条

查看id为5的数据
SELECT
id,
book_name,
bokk_author
FROM
book t
WHERE
t.bokk_author = "hhq" order by id limit 4,1

查第三,第四条
SELECT
id,
book_name,
bokk_author
FROM
book t
WHERE
t.bokk_author = "hhq" order by id limit 2,2

模糊查询like
SELECT
id,
book_name,
bokk_author
FROM
book t
WHERE
book_name like "%c%"

原文:http://blog.51cto.com/13496943/2145167

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!