954,560 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Procedure to enter data in table

Hello every1,

I want to ENTER Sr.No. and Name in the table using procedures.
My table has attributes
1. Sr.No. (which is my primary key(int datatype))
2. Name (which is not null(string datatype))

I want to write a procedure in mysql to automate the process of entering data in the table using procedures..It would be like ..

--At first table is empty
--CALL the procedure
--After Calling procedure table will have 400,000 (4lacs) entries..


Thanking you in advance
Thank You

shanker31
Newbie Poster
21 posts since Apr 2011
Reputation Points: 10
Solved Threads: 2
 

Consider the table name "Person"

shanker31
Newbie Poster
21 posts since Apr 2011
Reputation Points: 10
Solved Threads: 2
 

What exactly is your problem? Go ahead and code a procedure. Come back if it does not work and show us what you did.

smantscheff
Nearly a Posting Virtuoso
1,233 posts since Oct 2010
Reputation Points: 300
Solved Threads: 254
 
create procedure enter_data()
begin
declare x int default 0;
repeat
insert into Person values('AAAA');
x=x+1;
until X>10000
end repeat;
end //

this gives me an error :(

shanker31
Newbie Poster
21 posts since Apr 2011
Reputation Points: 10
Solved Threads: 2
 
What exactly is your problem? Go ahead and code a procedure. Come back if it does not work and show us what you did.

sorry for late reply...

shanker31
Newbie Poster
21 posts since Apr 2011
Reputation Points: 10
Solved Threads: 2
 

In collaborative debugging it's deemed good practice not only to state that an error occured but to cite the error message as precisely as possible.
Your code in my test installation gives not only one but two errors.
1) You have to set the delimiter to //
2) x = x + 1 is not a valid SQL statement. Probably you mean set x = x + 1
Also it's deemed good practice to stick to the spelling of variable names. Try this one:

delimiter //
create procedure enter_data()
begin
	declare x int default 0;
	repeat
		insert into Person values('AAAA');
		set x=x+1;
		until x > 10000
	end repeat;
end //
smantscheff
Nearly a Posting Virtuoso
1,233 posts since Oct 2010
Reputation Points: 300
Solved Threads: 254
 


@smantscheff How to enter random name in the table, i m aware of using rand() function but cant get the logic..

shanker31
Newbie Poster
21 posts since Apr 2011
Reputation Points: 10
Solved Threads: 2
 

You can get random strings with md5(rand())

smantscheff
Nearly a Posting Virtuoso
1,233 posts since Oct 2010
Reputation Points: 300
Solved Threads: 254
 

@smantscheff How to declare global variables:
is it like :
@@var=0;
or
set @@var=0;
or
set global var=0;

shanker31
Newbie Poster
21 posts since Apr 2011
Reputation Points: 10
Solved Threads: 2
 

This is a new question. Start a new thread with it and close this one.

smantscheff
Nearly a Posting Virtuoso
1,233 posts since Oct 2010
Reputation Points: 300
Solved Threads: 254
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You