当前位置:网站首页>我想造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;
后续:
边栏推荐
- [industry cloud talk live room] tomorrow afternoon! Focus on digital intelligence transformation of the park
- Yyds dry inventory Druid connection pool usage
- The performance of iron and steel enterprises was expected to be good in January this year. Since February, the prices of products of iron and steel enterprises have increased significantly. A mighty
- Quickly find five channels for high-quality objects, quickly collect and avoid detours
- Cloud native integration data warehouse heavy release
- Tetra - (4-pyridyl) porphyrin tpyp and metal complexes zntpyp/fetpyp/mntpyp/cutpyp/nitpyp/cotpyp/ptpyp/pdtpyp/cdtpyp (supplied by Qiyue porphyrin)
- MySQL'replace into'has a self incrementing ID of the pit. There is a problem with the backup opportunity
- I3wm get window class
- Record the dependent installation problems encountered in building the web assets when developing pgadmin
- Shengshi Haotong enterprise wechat sector creates a digital ecological community
猜你喜欢

Google Earth engine (GEE) 01- the prompt shortcut ctrl+space cannot be used

职场“大冤种”,不仅身累,心也被掏空……

Multisensor fusion sensing

执行npm install -g serve时报错权限权限问题解决方案

Redis series - redis startup, client day1-2

Opencv鼠标事件+界面交互之绘制矩形多边形选取感兴趣区域ROI

Solve psycopg2 NotSupportedError: PQconninfo not available in libpq < 9.3

Redis (4) -- Talking about integer set

Basic use of swiperefreshlayout, local refresh of flutterprovider

PyTorch-12 GAN、WGAN
随机推荐
ES cluster_ block_ exception read_ only_ allow_ Delete question
How to define a digital factory and what is the relationship with smart factory and industry 4.0
GMP model
[UVM practice] Chapter 2: a simple UVM verification platform (3) add various components to the verification platform
Redis(4)----浅谈整数集合
This paper analyzes the use method and implementation principle of eventbus event bus
JS modularization
Scratch program learning
Web technology sharing | webrtc recording video stream
Teach you how to use the harmonyos local simulator
Okhttp3 source code explanation (IV) cache strategy, disadvantages of Android mixed development
Which of the top ten securities companies has the lowest commission fee and is the most safe and reliable?
Redis series - five common data types day1-3
This article will take you to learn in detail what is FTTH
Google Earth engine (GEE) 02 basic knowledge and learning resources
ECE 9203/9023 analysis
Tsinghua Yaoban chendanqi won Sloan award! He is a classmate with last year's winner Ma Tengyu. His doctoral thesis is one of the hottest in the past decade
Yyds dry inventory executor package (executor function)
Error: the specified LINQ expression contains a reference to a query associated with a different context
Sanic based services use celery to complete dynamic modification timing tasks