免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
博客整理day34 數(shù)據(jù)庫sql操作

python day34 數(shù)據(jù)庫

一 創(chuàng)建表

增加表

create table 表名(    字段名 列表型[可選的參數(shù)], #必須加逗號    字段名 列表型[可選的參數(shù)]  #最后一行不加逗號)charset = utf8  #后面

增加數(shù)據(jù)

#語法insert into 表名(列1,列2) values (值1,值2);#例子insert into t1 (id,name) values (1,'momo');

查詢數(shù)據(jù)

#語法select 列1,列2 from 表名;  (*表示查詢所有的列)show tables;#列子select id,name from t1;

修改數(shù)據(jù)

#1.修改表名 語法alter table 舊表名 rename 新表名;alter table t1 rename t11;
#2.增加字段 語法#添加的列永遠(yuǎn)是添加在最后一列之后alter table 表名    add 字段名 列表型[可選的參數(shù)];    alter table t11 add name varchar(32) not null defaut '';#添加的列永遠(yuǎn)是添加在第一列alter table 表名    add 字段名 列表型[可選的參數(shù)] first;    alter table t11 add name varchar(32) not null defaut '' first;#添加的列永遠(yuǎn)是添加在....列之后alter table 表名 add 字段名 列表型[可選的參數(shù)] after 字段名;    alter table t11 add name varchar(32) not null defaut '' after age;
#3.刪除字段 語法alter table 表名 drop 字段名 ;    alter table t11 drop name;
#4.修改字段 語法#修改字段數(shù)據(jù)類型alter table 表名 modify 字段名 數(shù)據(jù)類型[可選的參數(shù)];    alter table t11 modify name char(30);#修改字段名和數(shù)據(jù)類型alter table 表名 change 字段名 字段名 數(shù)據(jù)類型[可選的參數(shù)];    alter table t11 change name name2 char(30) not null default '';

刪除數(shù)據(jù)

#刪除數(shù)據(jù) 語法drop table 表名;   drop table t1;

復(fù)制表結(jié)構(gòu)

create table t11 like t111;

二 查看表結(jié)構(gòu)

#方法一    describe 表名;#方法二    desc 表名;#方法三  查看創(chuàng)建表的SQL語句    show create table 表名

三 MySQL支持的數(shù)據(jù)類型

整型

類型大小范圍(有符號)范圍(無符號) unsigned用途
tinyint1字節(jié)(-128,127)(0,255)小整數(shù)值
smallint2字節(jié)(-32 768,32 767)(0,65 535)大整數(shù)值
mediumint3 字節(jié)(-8 388 608,8 388 607)(0,16 777 215)大整數(shù)值
int或integer4 字節(jié)(-2 147 483 648,2 147 483 647)(0,4 294 967 295)大整數(shù)值
bigint4 字節(jié)(-9 233 372 036 854 775 808,9 223 372 036 854 775 807)(0,18 446 744 073 709 551 615)大整數(shù)值
float4 字節(jié)float(255,30)(-3.402 823 466 E 38,-1.175 494 351 E-38),0,(1.175 494 351 E-38,3.402 823 466 351 E 38)0,(1.175 494 351 E-38,3.402 823 466 E 38)單精度 浮點數(shù)值
float8 字節(jié)double(255,30)(-1.797 693 134 862 315 7 E 308,-2.225 073 858 507 201 4 E-308),0,(2.225 073 858 507 201 4 E-308,1.797 693 134 862 315 7 E 308)0,(2.225 073 858 507 201 4 E-308,1.797 693 134 862 315 7 E 308)雙精度 浮點數(shù)值
decimal對DECIMAL(M,D) ,如果M>D,為M 2否則為D 2 double(65,30)依賴于M和D的值依賴于M和D的值小數(shù)值
#浮點型create table t1(    id int auto_increment primary key,    salary decimal(16,10),    num float)charset=utf8;#float : 精確到小數(shù)點兩位#decimal : 可以控制精確的小數(shù)點位 decimal(m,n) m是數(shù)字的總個數(shù)(負(fù)號不算),n是小數(shù)點后個數(shù)

字符串

類型大小用途
CHAR0-255字節(jié)定長字符串
VARCHAR0-65535 字節(jié)變長字符串
TINYBLOB0-255字節(jié)不超過 255 個字符的二進(jìn)制字符串
TINYTEXT0-255字節(jié)短文本字符串
BLOB0-65 535字節(jié)二進(jìn)制形式的長文本數(shù)據(jù)
TEXT0-65 535字節(jié)長文本數(shù)據(jù)
MEDIUMBLOB0-16 777 215字節(jié)二進(jìn)制形式的中等長度文本數(shù)據(jù)
MEDIUMTEXT0-16 777 215字節(jié)中等長度文本數(shù)據(jù)
LONGBLOB0-4 294 967 295字節(jié)二進(jìn)制形式的極大文本數(shù)據(jù)
LONGTEXT0-4 294 967 295字節(jié)極大文本數(shù)據(jù)
#char(長度):  定長create table t1(    id int unsigned auto_increment primary key,    name char(10) not null default 'momo')charset=utf8;#varchar(長度): 變長create table t2(    id int auto_increment primary key,    name varchar(10) not null default 'momo')charset=utf8;'''區(qū)別:    char: 定長, 無論插入的字符是多少個,永遠(yuǎn)固定占規(guī)定的長度    場景:        1. 身份證        2. 手機號 char(11)        3. md5加密之后的值,比如密碼 等 char(32)                        varchar: 變長, 根據(jù)插入的字符串的長度來計算所占的字節(jié)數(shù),但是有一個字節(jié)是用來保存字符串的大小的               注意:如果,不能確定插入的數(shù)據(jù)的大小,一般建議使用 varchar(255)'''

日期時間類型

類型大小 (字節(jié))范圍格式用途
DATE31000-01-01/9999-12-31YYYY-MM-DD年月日
TIME3'-838:59:59'/'838:59:59'HH:MM:SS時分秒
YEAR11901/2155YYYY年份值
DATETIME81000-01-01 00:00:00/9999-12-31 23:59:59YYYY-MM-DD\HH:MM:SS年月日時分秒
TIMESTAMP41970-01-01 00:00:00/2038 結(jié)束時間是第 2147483647 秒,北京時間 2038-1-19 11:14:07,格林尼治時間 2038年1月19日 凌晨 03:14:07YYYYMMDD\HHMMSS混合日期和時間值,時間戳
create table t1(    d date,    t time,    dt datetime);  

四 表的完整型約束

auto_increment : 自增

primary key : 主鍵索引,可以加快查詢速度,列的值不能重復(fù)

not null : 標(biāo)識該字段不能為空

default : 為該字段設(shè)置默認(rèn)值

#列子1create table t1(    id int,    name char(5))charset = utf8;#例子2create tabel t2(    id int auto_increment primary key,    name char(10))charset = utf8#例子3create table t3(    id int unsigned auto_increment primary key,    name char(10) not null defualt 'hello',    age int not null default 0)charset = utf8

五 枚舉

ENUM 中文名稱叫枚舉類型,它的值范圍需要在創(chuàng)建表時通過枚舉方式顯示。ENUM只允許從值集合中選取單個值,而不能一次取多個值。

create table t1 (    id int auto_increment primary key,    gender enum('male','female'))charset utf8;mysql> insert into t9 (gender) values ('male');#不是male或者female就會報錯

六 操作表數(shù)據(jù)行

#語法insert into 表名 (列1, 列2) values (值1,'值2');#例子insert into t1 (id, name) values (1, 'simple');

#語法delete from 表名 where 條件;#例子mysql> delete from t1 where id=1;delete from 表名;  #刪除表中所有的數(shù)據(jù)truncate 表名;     #沒有where條件的區(qū)別:     1. delete之后,插入數(shù)據(jù)從上一次主鍵自增加1開始, truncate則是從1開始    2. delete刪除, 是一行一行的刪除, truncate:全選刪除 truncate刪除的速度是高于delete的

#語法update 表名 set 列名1=新值1,列名2=新值2 where 條件;mysql> update t11 set name='momo' where id=1;

#語法select 列1, 列2 from 表名;  (*代表查詢所有的列)select * from t66 where id=1;#between..and...: 取值范圍是閉區(qū)間select * from t11 where id between 1 and 3;#避免重復(fù)DISTINCTmysql> select distinct name from t11;#通過四則運算查詢mysql> select name, age*10 as age from t1;# in 用法mysql> select * from t11 where id in (1,3,5);#like : 模糊查詢mysql> select * from t11 where name like 'm%';mysql> select * from t11 where name like '%o';mysql> select * from t11 where name like '%mo%';
來源:https://www.icode9.com/content-2-533951.html
本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊舉報
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
DedeCMS V5.6二次開發(fā)數(shù)據(jù)庫文檔
[原創(chuàng)]貢獻(xiàn)一個學(xué)生成績管理系統(tǒng)的代碼 - J2EE論壇 - JAVA論壇 - 編程論壇
mysql最大字段數(shù)量及 varchar類型總結(jié)
查看mysql數(shù)據(jù)庫及表編碼格式
Linux shell操作mysql數(shù)據(jù)庫深入解析
03.慢查詢
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服