mysql語句實現(xiàn)簡單的增、刪、改、查操作示例
本文實例講述了mysql語句實現(xiàn)簡單的增、刪、改、查操作。分享給大家供大家參考,具體如下:
1、創(chuàng)建db_shop數(shù)據(jù)庫,如果該數(shù)據(jù)庫不存在則創(chuàng)建
create database if not exists db_shop;
2、刪除數(shù)據(jù)庫,如果該數(shù)據(jù)存在就刪除
drop database if exists db_shop;
3、給db_shop創(chuàng)建數(shù)據(jù)表
use db_shop; drop table if exists tb_goods; CREATE TABLE tb_goods( `goodsId` int(11) NOT NULL AUTO_INCREMENT, PRIMARY KEY (`tb_goods`) );
4、根據(jù)舊表創(chuàng)建新表
create table tb_goods01 like tb_goods;
5、刪除數(shù)據(jù)表
drop table tb_goods01;
6、給一個表增加一列(一個字段)
alter tb_goods add column goodsName varchar(255) after goodsId;
注意:不寫after、before則默認添加到最后
7、刪除字段
alter table tb_goods drop column goodsName;
8、插入數(shù)據(jù)
insert into tb_goods (goodsId,goodsName) values (1002,'商品1');
9、查詢
查詢所有
select * from tb_goods;
查詢特定
select goodsName fromtb_goods;
模糊查找
select * from tb_goods like '%商品%';
10、更新數(shù)據(jù)表
update tb_goods set goodsName='商品2';
更多關(guān)于MySQL相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《MySQL查詢技巧大全》、《MySQL常用函數(shù)大匯總》、《MySQL日志操作技巧大全》、《MySQL事務(wù)操作技巧匯總》、《MySQL存儲過程技巧大全》及《MySQL數(shù)據(jù)庫鎖相關(guān)技巧匯總》
希望本文所述對大家MySQL數(shù)據(jù)庫計有所幫助。
相關(guān)文章
You must SET PASSWORD before execut
今天在MySql5.6操作時報錯:You must SET PASSWORD before executing this statement解決方法,需要的朋友可以參考下2013-06-06MYSQL必知必會讀書筆記第四章之檢索數(shù)據(jù)
MySQL是一種開放源代碼的關(guān)系型數(shù)據(jù)庫管理系統(tǒng)(RDBMS)。接下來通過本文給大家介紹MYSQL必知必會讀書筆記第四章之檢索數(shù)據(jù),感興趣的朋友一起學(xué)習(xí)吧2016-05-05