Creating a SQL script to insert data into a table (MySQL) - mysql

I sincerely apologize if this sounds like the most ridiculously beginner question, but I'm just starting to figure out SQL. It's more out of necessity than learning from the ground up. Thankyou for any help though, I sincerely appreciate it!
What I'm trying to do is create a script to insert data to the following table:
playercreateinfo_item.sql - github link to copy of the sql table
The fields/columns are race, class, itemid, amount.
How would I go about creating a script for this? From my basic understanding, it would be something like:
INSERT INTO playercreateinfo_item (race,class,itemid,amount)
VALUES (1,1,1,1);
But what else would I need? Like a header or footer? I'm honestly not even sure what a full script would look like for this! I also have to insert hundreds of different pieces of data, I'm not sure if there's an easy way to do it, or if I have to just do it manually. I'm so sorry if this is a horribly basic question, I'm just lost trying to learn. Thankyou so much in advance for any help! You guys are fantastic.

A SQL script is just a text file with SQL commands. Usually queries are separated with a semicolon.
No header or footer required.
Edit:
In case of inserting multiple tuples, you can do a batch insert with INSERT like this
INSERT INTO playercreateinfo_item (race,class,itemid,amount)
VALUES (1,1,1,1), (2,2,2,2), (3,3,3,3);

Related

SQL Implementation - Social Media Like Functionality

I am building a full stack app, that is kind of like Pinterest or Instagram.
I've gotten stuck, which is a horrible feeling, and I'd love any help I could get from any kind soul out there! :)
So I'm trying to implement the "like" functionality. As y'all know, you can like an entity once, and only once. What I wonder is how to constrain the database in such a way that a user can't like more than once. The way I thought I'd do this is to have a separate Like table like this:
Now of course, if I UNIQUE the user_id, then users can only like one thing on the website, which obviously would be a disaster, hah. So my question is, how do I kind of make sure there are no duplicate rows with exactly the same information in them? Or make some kind of CHECK condition when creating the table so that there can't be more than one row where the user_id and the artpoem_id match?
Or am I thinking about this the wrong way? Should I have like a separate Like table for each and every ArtPoem-entry, and then UNIQUE the user_id?
I would be SO grateful for any help, as this has been bugging me for days. Thank you kindly!
Problem solved! If anyone else sees this in the future, here's how it happened:
With the help of #Solarflare here who pointed me in the right direction, I did this in my ORM (TypeOrm):
Which yielded this raw SQL:
And now my database gives me this error below when I try to add an additional like-table entry with matching artpoemIds and userIds, which is just what I was looking for! Yippie and onwards!

MySQL: migrate some content of one table into another table with a different structure

Here is what I would like to do: I have an old vBulletin forum with a couple thousands of threads and replies. I developed a Laravel forum application myself and would like to migrate data from the old forum into the new one, even though the structure is completely different. What is more, in my new MySQL table I use base64 id's that I manually have to program. So I cannot use pure MySQL to fill this in I guess.
Essentially I need to do something like this:
Old table ---- new table
'thread' -> 'title'
'text' -> 'body'
and so on... plus the thing with the base64 id's.
Any idea how to approach this? I didn't quite find anything useful using search, probably because I wasn't looking for the right keywords. Thanks a lot!
Here's how to approach this kind of problem.
Start by doing a SELECT operation to generate a result set looking like your new table's columns. Maybe something like this will work for you.
SELECT thread AS title,
text AS body,
TO_BASE64(SHA2(UUID(), 224)) AS base64id
FROM old_table
(I guessed about what belongs in your base64id column. TO_BASE64(SHA2(UUID(), 224)) generates hard-to-guess pseudorandom values. You can use anything here.)
Once you're satisfied with your resultset, you can do
INSERT INTO new_table (title, body, base64id)
SELECT .... your select query
to put rows into the new table.

What is the best practice in Pentaho DI(Kettle) for converting a csv into a One to Many Relationship

I am new to Pentaho DI(formerly Kettle) and I am tasked with taking CSV data and populating tables in an RDBMS that are in a "One to Many" relationship.
Here is an example of how the CSV data is structured:
OrderID,CustomerName, Date,Total Cost,LineItemNumber, LineItemDesc,LineItemQty,LineItemCost
101655,Mary Smith,2016-02-08,6.25,1|2|3|4,Lettuce|Tomatoes|Green Onions|Cucumbers,1|2|4|2,1.00|2.50|0.75|2.00
NOTE: the multiple values are seperated by pipes(|)
I need to convert it into the following tables:
I have been looking into several ways of doing this but didn't want to miss something simple due to my inexperience. Any advise would be greatly appreciated.
I have come up with a solution but it looks awfully complicated.
Try using the Split fields to Rows STEP in PDI. Give Delimiter as | (pipe) and give the column/field that you want to split.
Check the Pentaho wiki for more.
Hope this helps :)

insert wordpress custom field content into wordpress post using SQL

I need a sql query that will allow me to take the contents of a Wordpress custom field and insert them into the existing post (post_content). I have thousands of record that I need to do this with.
My limited SQL knowledge isnt good enough to figure this out since the the custom fields are stored in the "wp_postmeta" table and the post content is stored in the "wp_posts" table.
Thanks
You don't need to (and you most definitely don't WANT to) use SQL to do what you want.
Since you haven't actually tried anything yet, you should take a look at Update Post Meta if you want to make sure all of your tables are populated correctly, and everything is referenced properly according to Wordpress' standards.
If you run into any issues with writing the actual code to handle this, please open a new question and show us what you've tried.
Good luck.

how can I add records through a query in access?

Before I remade this simple database, I was able to perform a query and update and insert new records from that query. I can no longer do this and can't figure out why.
I'm not very knowledgeable with access so any help would be greatly appreciated. I have a feeling that this may have something to do with the auto number column that no longer exists. Basically, it wouldn't allow me to change the data type after I had entered data into the table. I needed to do this to preserve the primary key as they match the client's records and cannot be changed.
If I understand you right you have a query that used to work (and insert records in a table) and now doewsn't work anymore? Can you post the SQL of the query and the structure of the table that you are inserting in? That will make it a lot easier for the rest of the world to help you.