Skip to content

Instantly share code, notes, and snippets.

@exemplum100
Created July 16, 2023 07:31
Show Gist options
  • Save exemplum100/a758df8d08f1dd17bd82e2e4048559b8 to your computer and use it in GitHub Desktop.
Save exemplum100/a758df8d08f1dd17bd82e2e4048559b8 to your computer and use it in GitHub Desktop.
Случайная генерация имен для наполнения БД
USE [sqlnames]
GO
/****** Object: StoredProcedure [dbo].[sp_generatenames] ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[sp_generatenames]
@genvalue INT
AS
BEGIN
DECLARE @rowcount INT ;
DECLARE @rowcountl INT ;
DECLARE @randrow INT ;
CREATE TABLE #l1 (id INT PRIMARY KEY IDENTITY, fname VARCHAR(50) , lname VARCHAR(50))
SELECT @rowcount=COUNT(1) FROM dig_names
SELECT @rowcountl=COUNT(1) FROM dig_lnames
WHILE (SELECT COUNT(1) FROM #l1) != @genvalue
begin
DECLARE @rand_row INT;
DECLARE @rand_rowl INT;
DECLARE @first VARCHAR(50)
DECLARE @last VARCHAR(50)
SET @rand_row=ROUND(RAND() * (@rowcount-1),0)+1;
SET @rand_rowl=ROUND(RAND() * (@rowcountl-1),0)+1;
SET @first= (SELECT names FROM dig_names WHERE id=@rand_row)
SET @last= (SELECT lname FROM dig_lnames WHERE id=@rand_rowl)
IF (SELECT is_male FROM dig_names WHERE names=@first) !=1
BEGIN
SET @last=@last+'а'
END
INSERT INTO #l1 VALUES (@first,@last)
PRINT '1'
END
SELECT * FROM #l1
END;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment