当前位置:网站首页>我想造SQL数据(存储结构)
我想造SQL数据(存储结构)
2022-06-26 07:43:00 【QuietSnow_wuyaya】
场景:
----上游给数不方便,同时不依赖对方给的数据。
----表里字段多,每次改很麻烦
方式:写存储结构
举个例子:
SET @myCompNo=DATE_FORMAT(NOW(),'666%y%m%d%H%i%s'); -- 解读:单号不想每次手动编,根据当前的年月日时分秒自动生成
-- 解读:表里插数,id不能重复一般设null,comp_no就是上面自动生成的,create_time要求生成15天前的,update_time一般设为当前时间
INSERT INTO alibb_ses.comp_info (id, comp_no, create_time, update_time)
VALUES (null, @myCompNo, date_sub(now(),interval 15 day),now());
-- 查造好的comp_no
select @myCompensatenNo;
(记得Ctrl A然后run……有一次一条一条运行人傻了)↑ 这是一个比较简单的例子。
如果要造更复杂一点的,用游标等等。比如我想造用户:
第一段:
create
definer = [email protected]`%` procedure create_user(IN name varchar(50), IN a int, IN house varchar(50))
BEGIN
-- 定义变量
DECLARE user_id bigint(15); -- 这个变量好像没用到
DECLARE house_id varchar(50);
DECLARE ro_id varchar(1024);
DECLARE b int;
-- 开启游标
SELECT bas_house_id into house_id from bas_house where house_code=house;
set b=1;
while b<=a DO
-- 循环开始
-- 更新表
INSERT INTO `user` (`USER_ID`,…………) VALUES (username, …………);
SELECT SYS_ROLE_ID into role_id from sys_role where ROLE_NAME='admin' ;
INSERT INTO `SYS_ROLE_USER` (……) VALUES (……);
set b = b+1;
end WHILE;
end;
第二段:调用
#造用户
CALL `create_user`('myName',1,'myHome');
#造好后查看数据
SELECT* FROM sys_user ORDER BY 1 DESC;
后续:
边栏推荐
- Golang source package collection
- Item2 installation configuration and environment failure solution
- js模块化
- Informatics Olympiad 1355: string matching problem (STRs)
- 一文搞懂Glide,不懂来打我
- Detailed materials of applying for residence permit in non local Beijing
- php array_ Merge details
- Yyds dry inventory executor package (executor function)
- 5,10,15,20-tetraphenylporphyrin (TPP) and metal complexes fetpp/mntpp/cutpp/zntpp/nitpp/cotpp/pttpp/pdtpp/cdtpp supplied by Qiyue
- What is the difference between bone conduction earphones and ordinary earphones? Advantages of bone conduction earphones
猜你喜欢

Exploration and practice of incremental data Lake in station B

Solution to the problem of multi application routing using thinkphp6.0

Niuniu looks at the cloud (greedy, hash, push formula) - the first session of Niuke winter vacation training camp

Redis series - five common data types day1-3

Yyds dry inventory kubernetes easy service discovery and load balancing (11)
![Jemter stress test - visualization tool - [usage]](/img/b1/3c367b690bbc16ae5a3e9e2c85af73.png)
Jemter stress test - visualization tool - [usage]
![Jemter stress test - Basic request - [teaching]](/img/f4/36dbd80e89d96e1121a6e2b92d1d07.png)
Jemter stress test - Basic request - [teaching]

MXNet对NIN网络中的网络的实现
![[industry cloud talk live room] tomorrow afternoon! Focus on digital intelligence transformation of the park](/img/20/05f0a2dfb179a89188fbb12605370c.jpg)
[industry cloud talk live room] tomorrow afternoon! Focus on digital intelligence transformation of the park

The first multi platform webcast of 2021ccf award ceremony pays tribute to the winners! CCF outstanding engineer
随机推荐
Liangshui Xianmu shows his personal awareness as a unity3d worker
js模块化
Solution to the permission problem when NPM install -g serve reports an error
Error: the specified LINQ expression contains a reference to a query associated with a different context
数据中心灾难恢复的重要参考指标:RTO和RPO
Which securities company has the lowest Commission for opening a mobile account? Is it safe to open an account online?
Apache InLong毕业成为顶级项目,具备百万亿级数据流处理能力!
A bold sounding and awesome operation - remake a Netflix
Shengshi Haotong enterprise wechat sector creates a digital ecological community
B站增量数据湖探索与实践
Webrtc has become the official standard of W3C and IETF, and mobile terminal development
[North Asia data recovery] a server data recovery method in which the partitions in the RAID5 array are formatted due to the misoperation of the NTFS file system
I3wm get window class
C#/. Net phase VI 01C Foundation_ 02:vs2019 basic operations, excluding code files, smart tips, data types, differences between float and double, and differences between string and string
Can the warehouse management system help enterprises reduce storage costs
Important reference indicators for data center disaster recovery: RTO and RPO
The difference between insert ignore and insert into
Jemter 壓力測試 -基礎請求-【教學篇】
php array_ Merge details
Xiaosha's counting (bit operation, Combinatorial Mathematics) - Niuke