Solved

Create a stored procedure to insert 1 million entries random values

Posted on 2015-01-16
3
245 Views
Last Modified: 2016-06-18
I need to Create a stored procedure to insert 1 million entries into my table tbl_student and execute it.

Columns:

int_enrollment_no(int),
pk_int_roll_no(int primarykey),
vchr_name(varchar),
vchr_city(varchar),
vchr_mobileno(varchar),
dat_dob(date)

Open in new window


These are the attributes, but the entries shouldn't be equal. I must insert random values. I need code for this.
0
Comment
Question by:jenthuz ojs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 25

Accepted Solution

by:
Tomas Helgi Johannsson earned 250 total points
ID: 40553171
Hi!

Take a look at this solution
http://kedar.nitty-witty.com/blog/generate-random-test-data-for-mysql-using-routines

You can easily modify this to your needs.

Regards,
     Tomas Helgi
0
 
LVL 8

Assisted Solution

by:Ganapathi
Ganapathi earned 250 total points
ID: 40553178
Use this as an example:
CREATE TABLE #TEST
(
	int_enrollment_no int,
	pk_int_roll_no int,
	vchr_name varchar(255),
	vchr_city varchar(255),
	vchr_mobileno varchar(10),
	dat_dob date
)

CREATE PROCEDURE INSERT_PROC
AS
BEGIN
	DECLARE @lnMIN INT,
			@lnMAX INT
	SELECT @lnMIN = 0		
			
	WHILE (@lnMIN < 100)
	BEGIN
		INSERT INTO #TEST
		SELECT
			CEILING(RAND() * 1000000),
			CEILING(RAND() * 10000000),
			CONVERT(varchar(255), NEWID()),
			CONVERT(varchar(255), NEWID()),
			CONVERT(VARCHAR(10),CEILING(RAND() * 1000000)),
			dateadd(second,(rand()*60+1),DATEADD(minute,(rand()*60+1) ,DATEADD(day,(rand()*365+1),DATEADD(year,-1,getdate()))) )
		SELECT @lnMIN = @lnMIN + 1
	END
END
GO
             
SELECT * FROM #TEST

Open in new window

0

Featured Post

Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating and Managing Databases with phpMyAdmin in cPanel.
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

626 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question