sql server 入門語句總結(jié)
對于數(shù)據(jù)庫來說多多少少要掌握一點(diǎn),首先基本的SQL語句要了解。下面來總結(jié)一些入門級別的SQL語句。
create相關(guān)
•show database; 顯示出現(xiàn)有的數(shù)據(jù)庫
•use database_x; 現(xiàn)在要使用數(shù)據(jù)庫database_x
•create table coffee (id int(5) not null,coffee_name varchar(25)); 創(chuàng)建一張表,包含id和coffee_name兩個字段
•alter table coffee add taste varchar(10); 增加新的一列
•insert into coffee (id,coffee_name,taste,rank) value ("1","BlueMountain",“well”,“5”); 插入數(shù)據(jù)
•show columns from coffee; 查看表結(jié)構(gòu)
•show create table coffee; 查看表信息,包括建表語句
•alter table student rename ss; 改變表名
•alter table ss drop mark; 刪除表ss中mark列
select語句
•select * from coffee where id="1"; 查詢出id=1的所有信息
•select coffee_name from coffee where id="2"; 查詢出id=2的coffee name
•select * from club where id between "1" and "3"; 查詢出id=1到3的條目
•select * from club where id="1" or id="3"; 查詢出id=1和id=3這兩個條目
•select club_name from club where mark>50; 查詢出mark大于50的club
•select club_name from club where mark not between 48 and 50; 查詢mark不在48與50之間的club
•select * from club where id in("1","3","4"); 查詢id=1,3,4的條目
•select * from club where id not in("1","3","4");
•select * from club where name like "M%r"; 通配符%表示任意長度的字符(可以是0,漢字為兩個字符)
•select * from club where name like "M_r"; _表示單個字符
•select * from club where id in("1","3","4") and mark>50; 多重查詢
•select * from club order by mark desc; 按照mark降序排列(desc:降序,usc:升序)
數(shù)量查詢相關(guān)
•select count(*) from club; 查詢club中有多少條記錄
•select count(distinct mark) from club; 不同分?jǐn)?shù)的有多少條記錄
•select sum(mark) from club; 積分總和
•select avg(mark) from club; 平均積分
•select max(mark) from club; 最高積分
•select min(mark) from club; 最低積分
update語句
•update club set mark=mark-8 where id="1"; id=1的俱樂部積分罰8分
delete語句
•delete from club where id="001"; 刪除id=001的俱樂部信息
以上語句都是SQL語句增刪改查最基本的部分,屬于入門級別,一定要掌握。
相關(guān)文章
MSSQL 數(shù)據(jù)庫備份和還原的幾種方法 圖文教程
MSSQL 數(shù)據(jù)庫備份和還原的幾種方法小結(jié),配有圖文,大家看了就知道了。2009-12-12在SQLserver數(shù)據(jù)庫之間進(jìn)行傳表和傳數(shù)據(jù)的圖文教程
這篇文章主要介紹了在SQLserver數(shù)據(jù)庫之間進(jìn)行傳表和傳數(shù)據(jù)的圖文教程,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-12-12sqlserver主鍵設(shè)計(jì)的注意點(diǎn)
在數(shù)據(jù)庫設(shè)計(jì)中,主鍵用于惟一地標(biāo)識表中的某一條記錄2012-07-07SQL語句練習(xí)實(shí)例之五 WMS系統(tǒng)中的關(guān)于LIFO或FIFO的問題分析
SQL語句練習(xí)實(shí)例之五 WMS系統(tǒng)中的關(guān)于LIFO或FIFO的問題分析,需要的朋友可以參考下。2011-10-10sql中count或sum為條件的查詢示例(sql查詢count)
在開發(fā)時,我們經(jīng)常會遇到以“累計(jì)(count)”或是“累加(sum)”為條件的查詢,下面使用一個示例說明使用方法2014-01-01SQL Server存儲過程中編寫事務(wù)處理的方法小結(jié)
這篇文章主要介紹了SQL Server存儲過程中編寫事務(wù)處理的方法,結(jié)合實(shí)例形式總結(jié)分析了三種存儲過程中編寫事務(wù)處理的方法,具有一定參考借鑒價值,需要的朋友可以參考下2016-03-03