《javaWeb之mysql基礎(chǔ)》要點(diǎn):
本文介紹了javaWeb之mysql基礎(chǔ),希望對您有用。如果有疑問,可以聯(lián)系我們。
mysql基礎(chǔ)
1)mysql存儲結(jié)構(gòu): 數(shù)據(jù)庫 -> 表 -> 數(shù)據(jù) sql語句
2)管理數(shù)據(jù)庫:
增加: create database 數(shù)據(jù)庫 default character utf8;
刪除: drop database 數(shù)據(jù)庫;
修改: alter database 數(shù)據(jù)庫 default character gbk;
查詢: show databases / show create database 數(shù)據(jù)庫;
3) 管理表:
選擇數(shù)據(jù)庫:use 數(shù)據(jù)庫;
增加: create table 表(字段名1 字段類型,字段名2 字段類型......);
刪除: drop table 表;
修改:
添加字段: alter table 表 add [column] 字段名 字段類型;
刪除字段: alter table 表 drop [column] 字段名;
修改字段類型: alter table 表 modify 字段名 新的字段類型;
修改字段名稱 : alter table 表 change 舊字段名 新字段名 字段類型;
修改表名稱: alter table 表 rename [to] 新表名;
查詢:
show tables / desc student;
4) 管理數(shù)據(jù):
增加: insert into 表(字段1,字段2,...) values(值1,值2.....);
刪除: delete from 表 where 條件;
修改: update 表 set 字段1=值1,字段2=值2...... where 條件;
查詢:
4.1)所有字段: select * from 表;
4.2)指定字段: select 字段1,字段2.... from 表;
4.3)指定別名: select 字段1 as 別名 from 表;
4.4 )合并列: select (字段1+字段2) from 表;
4.5)去重: select distinct 字段 from 表;
4.6)條件查詢:
a)邏輯條件 :and(與) or(或)
select * from 表 where 條件1 and/or 條件2
b)比較條件: > < >= <= = <> between and(在...之間)
select * from 表 where servlet>=90;
c)判空條件:
判斷null: is null / is not null
判斷空字符串: ='' / <>''
d)模糊條件: like
%: 替換任意個(gè)字符
_: 替換一個(gè)字符
4.7 分頁查詢:limit 起始行,查詢行數(shù)
起始行從0開始
4.8 排序: order by 字段 asc/desc
asc: 正序,順序
desc:反序,倒序
4.9 分組查詢:group by 字段
4.10: 分組后篩選: having 條件
SQL語句的分類:
DDL: 數(shù)據(jù)定義語言
create / drop / alter
DML:數(shù)據(jù)操作語句
insert / delete /update / truncate
DQL: 數(shù)據(jù)查詢語言:
select / show
《javaWeb之mysql基礎(chǔ)》是否對您有啟發(fā),歡迎查看更多與《javaWeb之mysql基礎(chǔ)》相關(guān)教程,學(xué)精學(xué)透。維易PHP學(xué)院為您提供精彩教程。
轉(zhuǎn)載請注明本頁網(wǎng)址:
http://www.fzlkiss.com/jiaocheng/7108.html