dcsxlh

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
统计
 

msyql讲解

1、单表的关键词必须

2、多表:

左右连接:

面试题:左连接和右连接的区别?

a、b表

左连接,左表为主,左表整个表显示,右表与左表相关联的数据就显示,不关联的数据以null显示;

右连接,右表为主,右表整个表显示,左表与右表相关联的数据就显示,不关联的数据以null显示;

3、索引:

普通索引、唯一索引、主键索引 

4、造数据

造数存储过程

 ================================

情况
场景一:存储内固定插入数据案例讲解:

通过存储过程在一个指定的空表中插入10条数据
delimiter //
drop procedure if exists pro4;
drop table if exists money;
create procedure pro4()
BEGIN
declare i int default 0;# 变量名称i int 数据类型 默认为0
create table money(id int primary key auto_increment,
money int(10)
);
while(i<10)DO
insert into money(money) values(100);
set i=i+1;
end while;
select * from money;
end
//
call pro4()

========================
delimiter //
drop procedure if exists bb; #增强存储的健壮性
create procedure bb()
BEGIN
declare i int default 0 ; #声明变量,i变量,数据类int ,默认值为0
while (i<10) DO
insert into aa(id) values (i);
set i=i+1;
end while;
select * from aa ;
end
//
call bb()


优化2插入数据:插入变量的值

优化3:插入表和变量的值
delimiter //
drop table if exists aa;
drop procedure if exists bb; #增强存储的健壮性
create procedure bb(in x int )
BEGIN
declare i int default 0 ; #声明变量,i变量,数据类int ,默认值为0
drop table if exists aa;
create table aa(id int(10),age int(10));
while (i<x) DO
insert into aa(id) values (i);
set i=i+1;
end while;
select * from aa ;
end
//
call bb(10)

场景二:存储灵活插入数据案例讲解:(需要插入多少条数据,就插入多少条)

delimiter //
drop table if exists money;
drop procedure if exists pro4;
create procedure pro4(in x int)
begin
declare i int default 0;# 变量名称i int 数据类型 默认为0
drop table if exists money;
create table money(id int primary key auto_increment,money int(10));
while(i<x)DO
insert into money(money) values(100);
set i=i+1;
end while;
select * from money;
end
//

call pro4(20)

面试题:

1、你会存储吗?存储的结构?怎么实现?

2、存储在工作中用来干嘛? 造数据

posted on   多测师_肖sir  阅读(59)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
 
点击右上角即可分享
微信分享提示