登錄MySQL服務(wù)器
mysql -u root -p
創(chuàng)建數(shù)據(jù)庫
create database samp_db character set gbk;
查詢所有數(shù)據(jù)庫
show databases;
創(chuàng)建表
use samp_db;
create table students(
id int unsigned not null auto_increment primary key,
name char(8) not null,
sex char(4) not null,
age tinyint unsigned not null,
tel char(15) null default "-"
);
向表中插入數(shù)據(jù)
insert into students values(NULL,"王剛" ,"男", 20,"13811371377");
insert into students values(NULL,"孫麗華" ,"女", 22,"18256973756");
insert into students values(NULL,"王永恒" ,"男", 23,"18812345678");
insert into students values(NULL,"李白" ,"男", 33,"17089898989");
查詢表中的數(shù)據(jù)
select * from students;
select name from students;
條件查詢
select * from students where sex="男";(查詢students表中男同學(xué))
select * from students where age=20;(查詢students表中年齡為20的學(xué)生)
更新表中的數(shù)據(jù)
update 表名稱 set 列名稱=新值 where 更新條件;
update students set age=21 where name="王剛";(將王剛的年齡改成21)
update students set tel=default where id=2;(將id為2的同學(xué)的手機(jī)號(hào)變成默認(rèn)值"-")
update students set name="張永恒",tel="1821324679" where name="王永恒";(將王永恒的名字改成張永恒,手機(jī)號(hào)改成18213245679)
刪除表中的數(shù)據(jù)
delete from 表名稱 where 刪除條件
delete from students where id=4;(刪除id=4的這個(gè)學(xué)生的數(shù)據(jù))
delete from students;(刪除表中所有數(shù)據(jù))
添加列
alter table 表名 add 列名 列數(shù)據(jù)類型 [after 插入位置];
alter table students add address char(60);(往students表中插入address列)
alter table students add birthday date after age;(向students表的age列之后插入birthday列)
修改列
alter table 表名 change 列名稱 列新名稱 新數(shù)據(jù)類型;
alter table students change tel telphone char(15) default "-";(將tel列名修改為telphone)
刪除列
alter table 表名 drop 列名稱;
alter table students drop birthday;(刪除students表中的birthday列)
重命名表
alter table 表名 rename 新表名;
alter table students rename workmates;(將students表名修改為workmates)
刪除整張表
drop table 表名;
drop table workmates;(刪除workmates表)
刪除數(shù)據(jù)庫
drop database 數(shù)據(jù)庫名
drop database samp_db;(刪除samp_db數(shù)據(jù)庫)
MySQL基本語法學(xué)習(xí)
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
相關(guān)閱讀更多精彩內(nèi)容
- 小學(xué)語文修改病句的方法 修改病句是小學(xué)語文考試中常見的題型,在修改病句之前,我們應(yīng)該清晰的了解有哪些病句現(xiàn)象,下面...
- java 與mysql對(duì)應(yīng)類型以及MySQl基本語法Mysql,Oracle,Java數(shù)據(jù)類型對(duì)應(yīng) Apache ...
- 一、SQL語句 如果要在程序運(yùn)行過程中操作數(shù)據(jù)庫中的數(shù)據(jù),那得先學(xué)會(huì)使用SQL語句 1.什么是SQL SQL(st...