1. 程式人生 > >常用數據庫操作語句(2)

常用數據庫操作語句(2)

數據 != 排序 編程 就是 int str 表結構 author

查看表結構
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%"

常用數據庫操作語句(2)