当前位置:网站首页>I want to create SQL data (storage structure)
I want to create SQL data (storage structure)
2022-06-26 07:43:00 【QuietSnow_ wuyaya】
scene :
---- Upstream feeding is inconvenient , At the same time, it does not rely on the data given by the other party .
---- There are many fields in the table , It's troublesome to change every time
The way : Write storage structure 
for instance :
SET @myCompNo=DATE_FORMAT(NOW(),'666%y%m%d%H%i%s'); -- Reading : I don't want to make the number manually every time , It is automatically generated according to the current year, day, hour, minute and second
-- Reading : Table interpolation ,id The general setting cannot be repeated null,comp_no It is generated automatically above ,create_time Request generation 15 The day before ,update_time It is generally set to the current time
INSERT INTO alibb_ses.comp_info (id, comp_no, create_time, update_time)
VALUES (null, @myCompNo, date_sub(now(),interval 15 day),now());
-- Check the made comp_no
select @myCompensatenNo;
( Remember Ctrl A then run…… Once, one by one, the operator was stupid )↑ This is a relatively simple example .
If you want to make something more complicated , Using a cursor, etc . For example, I want to create users :
The first paragraph :
create
definer = [email protected]`%` procedure create_user(IN name varchar(50), IN a int, IN house varchar(50))
BEGIN
-- Defining variables
DECLARE user_id bigint(15); -- This variable doesn't seem to be used
DECLARE house_id varchar(50);
DECLARE ro_id varchar(1024);
DECLARE b int;
-- Open cursor
SELECT bas_house_id into house_id from bas_house where house_code=house;
set b=1;
while b<=a DO
-- Loop start
-- Update table
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;
The second paragraph : call
# Make user
CALL `create_user`('myName',1,'myHome');
# Check the data after making
SELECT* FROM sys_user ORDER BY 1 DESC;
follow-up :
边栏推荐
- How to convert Unicode into Chinese characters in Excel
- OSPF design principles, commands take H3C as an example
- Here is the command to display the disk space usage. Go ahead and pay attention to more wonderful things!
- Can the warehouse management system help enterprises reduce storage costs
- MySQL storage and custom functions
- Jemter 压力测试 -可视化工具支持-【安装篇】
- 卡尔曼滤波器_Recursive Processing
- Detach an entity from jpa/ejb3 persistence context
- 技术分享 | MySQL:caching_sha2_password 快速问答
- 个人用指南针软件买股票安全吗?怎么炒股买股票呢
猜你喜欢
![[UVM basics] understanding of sequence and sequencer](/img/74/ff451e500d0b7154d7bb95398eaef0.jpg)
[UVM basics] understanding of sequence and sequencer

Apache inlong graduated as a top-level project with a million billion level data stream processing capability!
![Jemter stress test - visualization tool support - [installation]](/img/e9/9acda4e37c98cc21df9499684205c6.png)
Jemter stress test - visualization tool support - [installation]

Redis (4) -- Talking about integer set

Young man, do you know the original appearance of kotlin association process?

Multisensor fusion sensing

Teach you how to use the harmonyos local simulator

解决 psycopg2.NotSupportedError: PQconninfo not available in libpq < 9.3

数据中心灾难恢复的重要参考指标:RTO和RPO

What are the characteristics of digital factory in construction industry
随机推荐
Esp32-c3 introductory tutorial WiFi part ⑥ - WIFI intelligent distribution network based on serial port
Request&Response
Liangshui Xianmu shows his personal awareness as a unity3d worker
Machine learning - Iris Flower classification
Two models of OSPF planning: double tower Raider and dog tooth crisscross
Can the warehouse management system help enterprises reduce storage costs
A bold sounding and awesome operation - remake a Netflix
Shengshi Haotong enterprise wechat sector creates a digital ecological community
The difference between insert ignore and insert into
蓝桥杯嵌入式学习总结(新版)
[industry cloud talk live room] tomorrow afternoon! Focus on digital intelligence transformation of the park
Solution to the problem of multi application routing using thinkphp6.0
Class class of box selection four to and polygon box selection based on leaflet encapsulation
[UVM basics] TLM common data receiving and sending and data receiving examples
Tetradecanoxy tetraphenylporphyrin methacrylate mm-tpp-14c; Cetanoxy tetraphenyl porphyrin methacrylate mm-tpp-16c; Purple solid; Qiyue supply
Jmeter压力测试-Web代理本地接口测试【教学篇】
Record the dependent installation problems encountered in building the web assets when developing pgadmin
My colleague asked a question I never thought about. Why did kubernetes' superfluous' launch the static pod concept?
What are the key points of turnover box management in warehouse management
Database persistence