• This is a read only backup of the old Emudevs forum. If you want to have anything removed, please message me on Discord: KittyKaev

[SOLVED] Create rows from x id to x

Status
Not open for further replies.

jonmii

Enthusiast
Hi,

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?

Thanks
 

Portals

Banned
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.
 

Tommy

Founder
5yNsy9H.png


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.
 

jonmii

Enthusiast
That might work [MENTION=1]Tommy[/MENTION].

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

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

Thanks
 

Grandelf

Esteemed Member
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:
Code:
-- 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.
DELIMITER $$
-- 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)
BEGIN
    WHILE (_start <= _end) DO
        INSERT INTO creature_model_info(DisplayID) VALUES(_start);
        SET _start = _start + 1;
    END WHILE;
END$$
-- Change delimiter back to what it was.
DELIMITER ;
-- 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;
 
Last edited:

jonmii

Enthusiast
Thanks a lot! It worked fine.
Thanks to [MENTION=1]Tommy[/MENTION] too. His script helped me too.

Regards
 
Status
Not open for further replies.
Top