mysql語句實(shí)現(xiàn)簡單的增、刪、改、查操作示例
本文實(shí)例講述了mysql語句實(shí)現(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、給一個(gè)表增加一列(一個(gè)字段)
alter tb_goods add column goodsName varchar(255) after goodsId;
注意:不寫after、before則默認(rèn)添加到最后
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存儲(chǔ)過程技巧大全》及《MySQL數(shù)據(jù)庫鎖相關(guān)技巧匯總》
希望本文所述對大家MySQL數(shù)據(jù)庫計(jì)有所幫助。
版權(quán)聲明:本站文章來源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請聯(lián)系alex-e#qq.com處理。