首页 / MYSQL / mysql 基本指令 1
mysql 基本指令 1
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了mysql 基本指令 1,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3579字,纯文字阅读大概需要6分钟。
内容图文
![mysql 基本指令 1](/upload/InfoBanner/zyjiaocheng/502/549d5988c2564c24be9222b250c85b75.jpg)
desc 表名 --查看表属性 show create table 表名 \g; --查看代码 alter table 表名 auto_increment=20; --改自增的值
MySQL:自增步长
基于会话级别:
show session variables like ‘auto_inc%‘; --站看全局变量
set session auto_increment_increment=2; --设置会话步长
基于全局级别:
show global variables like ‘auto_inc%‘; --查看全局变量
set global auto_increment_increment=2; --设置会话步长
SQLServer:自增步长:
基础表级别:
create table ‘t1‘(
‘nid‘ int(11) not null auto_increment primary key,
‘pid‘ int(11) not null,
‘num‘ int(11) default null,
primary key(‘nid‘)
)ENGINE=InnoDB auto_increment=4, 步长=2 DEFAULT CHARSET=utf8
唯一索引:
create table t1(
id int ...,
num int,
xx int,
unique uq1 (num,xx)
)
PS:
唯一:
约束不能重复(可以为空)
PS:主键不能重复(不能为空)
加速查找 外键的变种:
a.用户表和部门表
用户:
1 alex 1
2 root 1
3 egon 2
4 laoyao 3
部门:
1 服务
2 保安
3 公关
====》 一对多
示列1
b. 用户表和博客表
用户表:
1 alex
2 root
3 egon
4 laoyao
博客表:
FK() + 唯一
1 /alex3714/ 4
2 /yuancheqi/ 1
3 /wupeiqi/ 1
====》一对一
create table userinfo1(
id int auto_increment primary key,
name char(10),
gender char(10),
email varchar(64)
)engine=innodb default charset=utf8;
create table admin(
id int not null auto_increment primary key,
username varchar(64) not null,
password varchar(64) not null,
user_id int not null,
unique uq_u1 (user_id),
constraint fk_admin_ul foreign key (user_id) references userinfo1(id)
)engine=innodb default charset=utf8;
示列2
用户表
主机表
用户主机关系表
====》 多对多
create table userinfo2(
id int auto_increment primary key,
name char(10),
gender char(10),
email varchar(64)
)engine=innodb default charset=utf8;
create table host(
id int auto_increment primary key,
hostname char(64)
)engine=innodb default charset=utf8;
create table user2host(
id int auto_increment primary key,
userid int not null,
hostid int not null,
unique uq_user_host (userid, hostid),
constraint fk_u2h_user FOREIGN key (userid) references userinfo2(id),
constraint fk_u2h_host FOREIGN key (hostid) references host(id)
)engine=innodb default charset=utf8;
分页:
select * from stu limit 1,10;
select * from stu limi;
select * from stu order by sni xxx desc;
排序:
select * from stu order by sni desc limit 2; 从大到小
select * from stu order by sni asc;从小到大 分组:
select count(id) from userinfo;
select count(id),part_id from userinfo1 group by part_id;
max
min
sum
avg
***** 如果对于聚合函数结果进行二次筛选时? 必须使用having ****
select count(id), part_id from userinfo1 group by part_id having count(id)>1; 连表操作:
select * from userinfo1,userinfo2;
select * from userinfo1,userinfo2 where userinfo1.part_id = userinfo2.id;
select * from userinfo1 left join userinfo2 on userinfo1.part_id = userinfo2.id
# userinfo2左边全显示
select * from userinfo right join userinfo2 on userinfo1.part_id = userinfo2.id
# userinfo2右边全显示
select * from userinfo1 innder join userinfo2 on userinfo1.part_id = userinfo2.id;
# 将出现null的行隐藏
select
work.id
from
work
left join userinfo1 on work.userinfo1_id = userinfo1.id
left join userinfo2 on work.userinfo2_id = userinfo2.id;
mysql 基本指令 1
标签:*** admin 表操作 基本 变量 arc Nid ssi div
本文系统来源:https://www.cnblogs.com/taozhengquan/p/9904193.html
内容总结
以上是互联网集市为您收集整理的mysql 基本指令 1全部内容,希望文章能够帮你解决mysql 基本指令 1所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。