創(chuàng)建,刪除和最基本查詢:
顯示數(shù)據(jù)庫 mysql->show databases;
創(chuàng)建數(shù)據(jù)庫 mysql->create database db;
刪除數(shù)據(jù)庫 mysql->drop database db;
選擇數(shù)據(jù)庫 mysql->use db
創(chuàng)建表 mysql->create table mytable(name varchar(20),sex(char(1),birth date);
刪除表 mysql->drop table mytable;
顯示表的內(nèi)容 mysql->show tables;
顯示表的結(jié)構(gòu) mysql->describe mytable;
更新:
1、對(duì)列的操作:
在一個(gè)表中增加一條字段 mysql->alter table yourtable add name varchar(20)not null;
刪除一個(gè)字段 mysql->alter table yourtable drop name ;
2、對(duì)行的操作:
插入一條記錄 mysql->insert into mytable values('summer','m','1983-08-24');
刪除一條記錄 mysql->delete from mytable where name='summer';
修改一條記錄 mysql->update mytable set sex='vm' where name='summer';
插入多條記錄 mysql->insert into mytable select *from yourtable;(
這種形式的INSERT 語句中,新行的數(shù)據(jù)值不是在語句正文中明確地指定的.而是語句中指定的一個(gè)數(shù)據(jù)庫查詢. 該查詢的邏輯限制:
»查詢不能含有ORDER BY子句. »查詢結(jié)果應(yīng)含有與INSERT語句中列數(shù)目相同的列,且數(shù)據(jù)類型必須逐列兼容. )
簡(jiǎn)單查詢:
1.在查詢結(jié)果中顯示列名
a.用as關(guān)鍵字:select name as '姓名' from students order by age
b.直接表示:select name '姓名' from students order by age
.精確查找:
a.用in限定范圍:select * from students where native in ('湖南', '四川')
b.between...and:select * from students where age between 20 and 30
c. 比較測(cè)試符:(包括=,<>,<,<=,>,>=)select * from students where name = '李山'
d.like:select * from students where name like '李%' (注意查詢條件中有“%”,則說明是部分匹配,而且還有先后信息在里面,即查找以“李”開頭的匹配項(xiàng)。所以若查詢有“李”的所有對(duì)象,應(yīng)該命令:'%李%';若是第二個(gè)字為李,則應(yīng)為'_李%'或'_李'或'_李_'。)
e.[]匹配檢查符:select * from courses where cno like '[AC]%' (表示或的關(guān)系,與"in(...)"類似,而且"[]"可以表示范圍,如:select * from courses where cno like '[A-C]%')注:關(guān)于這個(gè)字符我在mysql里用的時(shí)候mysql把它當(dāng)兩個(gè)普通自符處理的。
[^]stockname like '[^F-M]%' --------- (^排除指定范圍)
a.count()求總數(shù),如:select count(*) from students (求學(xué)生總?cè)藬?shù))
b.avg(列)求平均,如:select avg(mark) from grades where cno=’B2’
c.max(列)和min(列),求最大與最小
posted on 2007-04-22 20:59
靜兒 閱讀(895)
評(píng)論(0) 編輯 收藏