一、怎樣查看數(shù)據(jù)庫(kù)信息?
desc 數(shù)據(jù)庫(kù)名;
?
二、怎樣查看數(shù)據(jù)表信息?
desc 表名; ? ? ? ? ?//查看表的屬性和屬性值
或者用select語(yǔ)句: //查看表的行記錄信息
select * from 表名 (where nub='100001');
三、將數(shù)據(jù)寫(xiě)入數(shù)據(jù)庫(kù)要經(jīng)過(guò)什么步驟?
1. 創(chuàng)建表:
? ? create datable 數(shù)據(jù)庫(kù)名;
2. 創(chuàng)建用戶(hù):
? ? grant select,create,drop on stud.* to 用戶(hù)名@localhost identitied by "密碼"; //(注意雙引號(hào))
3.創(chuàng)建(多個(gè))空表,添加表的屬性和主鍵 :
? ? create table 表名(...主鍵..);
4.增加主鍵:
?
?
Alter
table 表名 add primary key (屬性名1,屬性名2);
5.
列
屬性字段操作(
都是用alter 開(kāi)頭
):
? ?5.1增加一個(gè)列(即屬性):
? ? ? ?
Alter table 表名
add
屬性名 varchar(40) not null;
? ?5.2?修改列字段名稱(chēng):(例如修改列屬性名稱(chēng)和屬性: )
Alter table 表名
change
name 新名字 varchar(20)(必須加上格式限制) not null;
5.3 修改列字段屬性值:(例如改成varchar(30):)
Alter table 表名
modify
屬性名 屬性新值(例如varchar(30)) not null;
? ?5.4.刪除列字段:
Alter table 表名
drop
column 屬性列名;
6. 行 記錄操作( insert ,update ,delete ):
? ?6.1. 往空表里插入行數(shù)據(jù)(即記錄):
insert into 表名 values('','','',..); //(單引號(hào)) 。注意增加列是alter,增加行是insert
? ?6.2.修改(更新)行信息:
? ?
update 用戶(hù)名 set 行某個(gè)屬性="該行修改后的屬性?xún)?nèi)容" where ... //注意單引號(hào)
例如:update std_info set name='張三豐' where nub='100001'; ? ? ?//將原記錄中名字“張三”改成“張三豐”
6.3刪除表某一行信息(即記錄):
? ? ? ? delete from 表名 where ..='...'; //注意delete 是直接接著from
7.刪除某個(gè)表:
drop table 表名;
四、查詢(xún)有哪幾種:
1.有序order查詢(xún):
?
select * from 表名 order by 屬性名 desc; //默認(rèn)升序 。有order?by就沒(méi)有where
2.分組group查詢(xún):
?select .. from 表名 group by 屬性名(例如:class,sex); //有g(shù)roup by就沒(méi)有where
3.查詢(xún)表中行總數(shù)(記錄總數(shù)):
? select count(*) from 表名;
3.多個(gè)表聯(lián)合查詢(xún):
select avg(b.score)
as
'平均分'
//查詢(xún)可以用as重用名
f
rom
std_info a,score_info b,curricula c
//表名可以直接重用名
where a.nub=b.nub and b.code=c.code and c.Curlum='英語(yǔ)' and a.class='9701';
4. 查看平均分:
select a.curlum as '課程名',avg(score) from curricula a,score_Info b where
a.code=b.code group by a.code;
注意:
?
1.四個(gè)聚合函數(shù)不能搭配order by。只能group by??
2.group by 有一個(gè)原則,就是 select 后面的所有列中,沒(méi)有使用聚合函數(shù)的列,必須出現(xiàn)在 group
by 后面。最常用的四個(gè)聚合函數(shù):count,avg,min,max。
?
?
??
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號(hào)聯(lián)系: 360901061
您的支持是博主寫(xiě)作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對(duì)您有幫助就好】元
