sql語句大全
來源:易賢網(wǎng) 閱讀:1203 次 日期:2015-08-12 15:02:39
溫馨提示:易賢網(wǎng)小編為您整理了“sql語句大全”,方便廣大網(wǎng)友查閱!

1、創(chuàng)建數(shù)據(jù)庫: create database <數(shù)據(jù)庫名>;

如:create database student;

2、連接到一個已經(jīng)存在的數(shù)據(jù)庫: use <數(shù)據(jù)庫名>;

如:use student;

3、刪除數(shù)據(jù)庫:drop database <數(shù)據(jù)庫名>;

如: drop database student;

4、創(chuàng)建表:create table <表名>(<列名><列的數(shù)據(jù)類型>[<列的約束>])

如:create table stuinfo(stuid int primary key,stuname varchar(20) not null)

5、刪除表: drop table <表名>

如: drop table stuinfo;

6、修改表:alter table

給表添加新列: alter table <表名> add <列名><列的數(shù)據(jù)類型>;

添加多列,中間用逗號隔開

如:alter table stuinfo add stugender varchar(10)

修改某列的數(shù)據(jù)類型:alter table <表名> modify <列名><新數(shù)據(jù)類型>

如:alter table stuinfo modify stugender int

修改列名:alter table <表名> change <老列名><新列名><數(shù)據(jù)類型>

如:alter table stuinfo change stuname stuaddress varchar(30)

刪除列:alter table <表名> drop <列名>

如: alter table stuinfo drop stugender

7、將創(chuàng)建的表的語句反向?qū)С觯?show create table <表名>

8、查詢表的所有內(nèi)容:select * from <表名>

查詢表的部分內(nèi)容: select <列名列表> from <表名>

9、查詢表結(jié)構(gòu):show columns from <表名>

10、插入單行數(shù)據(jù):insert into <表名>(<列名列表>) values(<值列表>)

11、插入多行數(shù)據(jù):作用相當于將數(shù)據(jù)從一個表復(fù)制到另一個表

insert into <表名> (列名列表) select

如將stuinfo表中的所有的學(xué)生姓名復(fù)制到students表中的stuname列中:insert into students(stuname) select stuname from stuinfo

12、刪除數(shù)據(jù):delete from <表名> where<過濾條件>

如刪除stuid為4的人的數(shù)據(jù):delete from stuinfo where stuid=4

更多信息請查看IT技術(shù)專欄

更多信息請查看數(shù)據(jù)庫
易賢網(wǎng)手機網(wǎng)站地址:sql語句大全
由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇剩?/div>
關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 加入群交流 | 手機站點 | 投訴建議
工業(yè)和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網(wǎng)安備53010202001879號 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號
聯(lián)系電話:0871-65317125(9:00—18:00) 獲取招聘考試信息及咨詢關(guān)注公眾號:hfpxwx
咨詢QQ:526150442(9:00—18:00)版權(quán)所有:易賢網(wǎng)