当前位置:网站首页>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 :
边栏推荐
- SQL
- D do not assign references to non domain parameters
- CMDA 3634 image processing
- [NLP] vector retrieval model landing: Bottleneck and solution!
- Deeply analyze storage costs and find cost reduction solutions
- Encapsulating ranging and surface class based on leaflet
- Important reference indicators for data center disaster recovery: RTO and RPO
- Redis (4) -- Talking about integer set
- How to quickly merge multiple PDF files?
- Systemctl PHP configuration file
猜你喜欢

Request&Response

Google Earth engine (GEE) 02 basic knowledge and learning resources

PyTorch-12 GAN、WGAN

Important reference indicators for data center disaster recovery: RTO and RPO

Gavin teacher's insight on transformer live class - multi state transition of financial BOT and rasa interactive behavior analysis of Rasa project (52)

Two models of OSPF planning: double tower Raider and dog tooth crisscross

少年,你可知 Kotlin 协程最初的样子?

Solution to the permission problem when NPM install -g serve reports an error

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
![Jemter stress test - basic requirements - [teaching]](/img/f4/36dbd80e89d96e1121a6e2b92d1d07.png)
Jemter stress test - basic requirements - [teaching]
随机推荐
Cloud native integration data warehouse heavy release
[UVM practice] Chapter 2: a simple UVM verification platform (5) build test cases
Yyds dry inventory kubernetes easy service discovery and load balancing (11)
What are the key points of turnover box management in warehouse management
GMP model
Oracle creates stored procedures with return values and executes SQL calls
Jemter stress test - Basic request - [teaching]
记一次开发 pgadmin 时执行 Building the Web Assets 遇到的依赖安装问题
1010. song backtracking with total duration divisible by 60
信息学奥赛一本通 1355:字符串匹配问题(strs)
Which of the top ten securities companies has the lowest commission fee and is the most safe and reliable?
A bold sounding and awesome operation - remake a Netflix
This article will take you to learn in detail what is FTTH
OSPF design principles, commands take H3C as an example
Junit
In interface testing, several methods to verify the success of deleting interfaces
Jemter 压力测试 -可视化工具支持-【安装篇】
Database persistence
How to convert Unicode into Chinese characters in Excel
Cache usage