Random name generation method

Time:2020-9-26

 Transferred from: http://www.maomao365.com/?p=10025

Abstract:
The method of generating Chinese names using SQL script is as follows:
Experiment environment: SQL Server 2008 R2
In our work, we sometimes need to generate random names in batches. The following describes how to use SQL scripts to generate random “names”, as shown below:
Realization idea:
1. Define a family name database
2. Define a name base
3. Use Rand to select random rows and combine them into a new name

DECLARE @maomao_Xing TABLE(keyId INT IDENTITY(1,1) PRIMARY KEY, NAME NVARCHAR(20)) 
DECLARE @maomao_Ming TABLE(keyId INT IDENTITY(1,1) PRIMARY KEY, NAME NVARCHAR(20)) 

INSERT @maomao_Xing VALUES
('zhao '), ('qian'), ('sun '), ('li'), ('xi '), ('wu'), ('zheng '), ('wang'), ('feng '), ('chen'), ('chu '), ('wei'), ('jiang '), ('shen'), ('han '), ('yang'),
('zhu '), ('qin'), ('You '), ('xu'), ('he '), ('lv'), ('shi '), ('zhang'), ('kong '), ('cao'), ('yan '), ('hua'), ('jin '), ('wei'), ('tao '), ('jiang'),
Qi, Xie, Shui, Dou, Zhang, Yun, Su, pan, Ge, Xi, fan, Peng and Lang,
('lu '), ('wei'), ('chang '), ('ma'), ('miao '), ('feng'), ('hua '), ('Fang'), ('yu '), ('ren'), ('yuan '), ('liu'), ('feng '), ('bao'), ('shi '), ('tang'),
('fei '), ('Lian'), ('cen '), ('xue'), ('lei '), ('he'), ('ni '), ('tang'), ('teng '), ('yin'), ('luo '), ('bi'), ('hao '), ('wu'), ('An '), ('chang'),
('le '), ('yu'), ('shi '), ('fu'), ('pi '), ('bian'), ('qi '), ('kang'), ('yu '), ('yuan'), ('bu '), ('gu'), ('meng '), ('ping'), ('huang '),
('he '), ('mu'), ('xiao '), ('yin'), ('lai ')

INSERT @maomao_ Ming values ('ai '), ('An'), ('bai '), ('bang'), ('bao '), ('bao'), ('bao '), ('bao'), ('bei '), ('bei'), ('ben '),
('bi '), ('bi'), ('bi '), ('bin'), ('bing '), ('bing'), ('bu '), ('cai'), ('cao '), ('chang'), ('chang '), ('chang'), ('chang '),
('chao '), ('chen'), ('chen '), ('cheng'), ('cheng '), ('cheng'), ('chong '), ('chu'), ('chuan '), ('chun'), ('tsui '), ('village'),
('dian '), ('ding'), ('ding '), ('dong'), ('dong '), ('dong'), ('er '), ('fan'), ('Fang '), ('Fang'), ('fei '), ('fei'), ('fen '),
('fen '), ('feng'), ('feng '), ('feng'), ('fu '), ('fu'), ('fu '), ('fu'), ('fu '), ('fu'), ('gai '), ('gang'), ('gao '), ('ge'),
There are four kinds of plants, namely, Cr, gen, Geng, Gong, Guan, Guang, GUI, Guo, Hai and Han,
There are two kinds of Chinese characters: Han, Hao, Hao, he, Hong, Hong, Hou, Hua, Cun, Da, Dan and Dao,
('de '), ('deng'), ('di '), ('dian'), ('dian '), ('dian'), ('xiao '), ('dog'), ('qin ')


declare @t table(name nvarchar(3))
declare @i int 
set @i=0

while @i <1000
begin
insert into @t (name) 
SELECT RTRIM((SELECT NAME FROM @maomao_Xing WHERE keyId = Round(Rand()*(100-1)+1,0)))
+RTRIM(LTRIM((SELECT NAME FROM @maomao_Ming WHERE keyId = Round(Rand()*(100-1)+1,0))))
+RTRIM(LTRIM((SELECT NAME FROM @maomao_ Ming where keyID = round (rand() * (100-1) + 1,0))) as [random name]
set @i [email protected]+1 
end

select * from @t as t

 

Related reading:
The RAND mathematical function will return a float type of 0 ~ 1
Method sharing of random query data in database table

Recommended Today

Multithreading foundation of multithreading series (1)

Thread related concepts Before learning about multithreading, let’s take a look at a few concepts related to multithreading. process: process is the concept of computer. The program occupies the total of all computing resources when the server is running. An application program is a process when it runs. Open the task manager of windows, as […]