View Full Version : [SOLVED] Create rows from x id to x

04-14-2016, 01:37 AM

I want to import a lot of models to de db.
I want to create from id 35000 to id 36383 and field with default data.

How can i make it in 1 query?


04-14-2016, 03:54 AM
Not sure but this might be the wrong section, this seems more along the lines of looking for support. But on topic im not sure on how exactly to create something from start id to end id you might have to do it by hand.

04-14-2016, 05:20 AM

Moved. Seriously, how hard is it for members to read? It SPECIFICALLY STATES THAT TrinityCore -> [Sections] IS A RELEASE SECTION, which means SUPPORT THREADS AREN'T ALLOWED. I'm starting to think people are doing it on purpose. Just because you see "SQL" and your question is related to SQL doesn't mean you can post in any section related to SQL.

What do you mean by "models" and "default data"? That could be elaborated because if I were to create an example I wouldn't know what to input in the INSERT query. Regardless, you can do this programmatically instead of doing it one by one.

For example: http://paste2.org/P5NNLhXL
And here's the code (it is php because I had this website already opened, don't hate): http://sandbox.onlinephpfunctions.com/code/310b79748bfa1357146d0295d089d8a29712f15a

Pretty sure you can come up with a for loop in SQL to do this too, but I'm not that big into doing stuff like that in SQL.

04-14-2016, 12:25 PM
That might work Tommy.

The table that im working is creature_model_info
I just want to create that entries and other columns should have default values.

Just with 0 values BoundingRadius, CombatReach, Gender, DisplayID_Other_Gender.


04-14-2016, 01:17 PM
A way to do it in SQL is using a while loop.
Unfortunatly, you can only use while loops inside triggers, procedures etc.
Here's how you could do it:

-- Variables
SET @start_id := 35000;
SET @end_id := 36383;
-- Drop procedure, if it still exists, somehow..
DROP PROCEDURE IF EXISTS populate_creature_model_info;
-- Change delimiter, so we can create the procedure.
-- Procedure that will populate the table.
-- Unfortuntatly, we can't use a while loop outside a 'begin' and 'end' block.
CREATE PROCEDURE populate_creature_model_info(_start INT, _end INT)
WHILE (_start <= _end) DO
INSERT INTO creature_model_info(DisplayID) VALUES(_start);
SET _start = _start + 1;
-- Change delimiter back to what it was.
-- Delete already existing data.
DELETE FROM creature_model_info WHERE DisplayID BETWEEN @start_id AND @end_id;
-- Call the procedure and populate the table.
CALL populate_creature_model_info(@start_id, @end_id);
-- Drop procedure
DROP PROCEDURE IF EXISTS populate_creature_model_info;

04-14-2016, 02:47 PM
Thanks a lot! It worked fine.
Thanks to Tommy too. His script helped me too.