Skip to content
Advertisement

Tag: mysql

BatchSqlUpdate – how to get auto generated keys

I am using spring BatchSqlUpdate to insert a set of rows. How do I get the auto generated keys for all of the rows inserted? When doing a single insert I get the keys like this – Thanks! Answer There is no provided solution for this using BatchSqlUpdate as far as I know, but you can always query the last

MySQL syntax: What is this?

My exported SQL file contains the lines below: What do these lines mean, unlike CREATE TABLE and INSERT INTO? Answer They are variable assignments. The assignments are wrapped in executable comments in such a way that they are executed when MySQL is used and left alone if some other RDBMS is used. Furthermore, the 40101 indicates that the comments are

Count number of occurrences in SQL

I have a table with the following structure: (table_name, column_name) and for each row in this table I need to query the column_name in the table_name and do a COUNT(column_name) GROUP BY …

Prevent operational risk with SQL-dependent architecture

I am currently working on a very critical tool, which has a strong dependency to a MySQL database. This particularly means that if the SQL server goes down some day, all users won’t be able to use the application, since it is retrieving their configuration stored in database and launches components defined in DB, and a configuration is absolutely required

Select a list of keys of a table in MySQL

Say I have a table “products” and I would like to check if this table has any indexes, foreign keys etc A “DESCRIBE products” would give some information. Mainly the key field in the case. But defenietly no references and what table is linked to who etc etc. What is the best way to get such information via SQL about

Calculate age in MySQL (InnoDB)

If I have a person’s date of birth stored in a table in the form dd-mm-yyyy, and I subtract it from the current date, what format is the date returned in? How can I use this returned format to calculate someone’s age? Answer If the value is stored as a DATETIME data type: Less precise when you consider leap years:

Importing records from PostgreSQL to MySQL

Was wondering if anyone had any insight or recommended tools for exporting the records from a PostgreSQL database and importing them into a MySQL database. I believe the table structure is 100% identical. Thoughts? Thanks! Answer The command will generate SQL-standard-compliant INSERT statements with all column names listed and one VALUES clause per INSERT. This is the most portable way

How to convert last insert id into string?

I have a create account page and on the page I have one button to insert all the details into two seperate tables one of the tables Pictures is dependant on the User table 1:1 relationship via UserID. I have written some code to try get the last insert id so I can insert into the pictures table: Not sure

How to do a batch insert in MySQL

I have 1-many number of records that need to be entered into a table. What is the best way to do this in a query? Should I just make a loop and insert one record per iteration? Or is there a better way? Answer From the MySQL manual INSERT statements that use VALUES syntax can insert multiple rows. To do

Advertisement