亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

mysql數(shù)據(jù)表創(chuàng)建、增刪改查及關系表創(chuàng)建

原創(chuàng) 2018-12-14 14:15:15 343
摘要:-- 創(chuàng)建表 drop table if exists user; create table user( `id` mediumint(5) not null auto_increment comment '主鍵', `name` varcha
-- 創(chuàng)建表
drop table if exists user;
create table user(
`id` mediumint(5) not null auto_increment comment '主鍵',
`name` varchar(100) not null default '' comment '用戶名',
`sex` tinyint(2) comment '性別:0男;1女',
`age` tinyint(3) unsigned comment '年齡',
`email` varchar(200) not null default '' comment '郵箱',
`password` char(40) not null default '' comment '密碼',
`status` tinyint(1) not null default 0 comment '用戶狀態(tài):0未啟用;1啟用',
`create_time` int(10) not null default 0 comment '注冊時間',
primary key(`id`) using btree,
unique index `name`(`name`) using btree
);
-- 插入
insert into `user` values(null,'楊康',0,26,'yk@php.com',sha1(123456),1,1543223803),(null,'歐陽克',0,25,'oyk@php.com',sha1(123456),1,1543223867);
insert into `user`(`name`,`sex`,`age`,`email`,`password`,`status`,`create_time`) values('華箏',1,18,'hzh@php.com',sha1(123456),1,1543225896);
-- 更新
update `user` set `age` = 26,`status` = 0 where id = 4;
-- 查詢
select `name`,`sex`,`age`,`email`,`status` from `user` where `status` = 1 order by `age` desc limit 2;
-- 執(zhí)行簡單運算
select 15*2 `res`; 
-- 拼接字符串(直接拼接)
select concat(`id`,`name`) `user_str` from `user` where `status` = 1; 
-- 拼接字符串(兩個拼接的字符串之間有自定義連接符號)
select concat_ws(':',`id`,`name`) `user_str` from `user` where `status` = 1; 
select count(`id`) `num` from `user` where `status` = 1; 
-- 刪除
delete from `user` where `id` = 5;



當表中的某一字段在多條記錄中有可能重復時可能造成資源占用或者影響查詢,此時可以考慮將一張表分成多張表,用多張表的id進行關聯(lián),從而使查詢更快,后期的擴展更容易。


批改老師:韋小寶批改時間:2018-12-14 14:32:44
老師總結:寫的很不錯!mysql中的任何操作都是非常重要的!課后一定要好好練習!

發(fā)佈手記

熱門詞條