I am pretty sure MySQL does not have the INSERT INTO table OUTPUT [column value] that MSSQL does - http://msdn.microsoft.com/en-us/library/ms177564.aspx (or http://blogs.msdn.com/b/sqltips/archive/2005/06/13/output-clause.aspx)
What's an easy way to replicate this? (I am moving a MSSQL app to MySQL. The 'OUTPUT' is a unique identifier and a int currently, so maybe I could just SELECT MAX (int) and add one, and generate a UID prior to insert?)
Thanks
You can use the INSERT OR REPLACE statement to write new rows or replace existing rows in the table. The syntax and behavior of the INSERT OR REPLACE statement is similar to the INSERT statement. Unlike the INSERT statement, the INSERT OR REPLACE statement does not generate an error if a row already exists.
The Output is located at the bottom of MySQL Workbench. Its select box includes the Action Output , History Output , and Text Output options.
Once we insert a row in a table, the @@IDENTITY function column gives the IDENTITY value generated by the statement. If we run any query that did not generate IDENTITY values, we get NULL value in the output. The SQL @@IDENTITY runs under the scope of the current session.
If you are using Insert or Insert into both will insert the data in Table. However Insert into is basically used to fatch the data from another table using select command and insert into table where you want to insert the data.
If this value is an auto-increment field, you can run SELECT LAST_INSERT_ID();
after running the insert, and you'll get the last value inserted into this field.
See: http://dev.mysql.com/doc/refman/5.0/en/information-functions.html#function_last-insert-id
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With