What is the alternative for table valued parameters in MySQL? - mysql

I use table value parameter to send multiple rows of data to stored procedure in SQL Server and now since I am migrating to MySQL I want to know if their is an alternative to table valued parameter in MySQL.

Related

Stored procedure to get table data from different database

Can we get table data from multiple database using stored procedure?
Yes you can. You need to access table using database name.
e.g.
Select * From myDb1.Table1
Select * From myDb2.Table2
Make sure you have access to both the database or both the databases are linked if they are on different servers

Where does mysql server store the stored procedure code?

In MS SQL Server, it lets you search across all the stored procedures for the instance of some text. Does this exist in MySQL?
This is useful for trying to understand what the impact of changing the schema would be.
"Show me all the code that involves TableX"
How would you query across all stored procedures?
The procedures are stored in table mysql.proc. The code is in column body.
So you could query:
SELECT db, name, body FROM mysql.proc WHERE body REGEXP '[[:<:]]tablename[[:>:]]'

MySQL Create table with procedure analyze()

Procedure Analyse() suggests the optimal field for my columns. I want to create a new table with optimal field types starting from a table that I already have. At this time I'm running
SELECT * FROM mytable PROCEDURE ANALYSE();
Then I copy the report and manually I write the create statement. Is there a way to do that automatically? Is it more efficient to alter a table with new field types or create a new empty table with optimal field types and re-import data?
In truth you would not want to blindly accept the data types returned by this Analysis as you would / could never be sure what data types were "suggested". This Procedure returns "Suggested" optimal data types that "May" help reduce data storage requirements. The return values also depend on the data in the table you're selecting and could possibly change each time you run this query on new data.
Read more here on dev.mysql
But if you wanted to try something, I would start by building a Procedure of my own that could pass the returned data types recommended into a dynamically created DDL statement that you would need to check for possible incorrect datatypes and then execute the resulting DDL. It might take a little working out in terms of your code but you really should read more on Procedure Analyze()

Handling comma separated strings as a table in MySQL

I'm using SSRS with MySQL and need to handle the multi-select parameters from SSRS going into my routines (stored procedures) in MySQL.
SSRS passes a multi-select parameter as a comma separated string:
"1,2,3,4"
The common way this is done in SQL Server is by using a table-valued function that would return a table with a row for each value. You then join to this table and all is well.
What is the best way to handle this situation in MySQL, due to the fact that it does not have an equivalent table valued function?
I have seen suggestions to use a temp table in a function, however I will have multiple simultaneous calls of this so that will most likely not work.

SQL Server stored procedure for inserting multiple rows in one table and single row in other table

I am in need of a stored procedure for sales transaction. In a single SP I need to store CustomerID in one table and list of products purchased (multiple rows) in another table.
Can any one give me an best example?
Thanks in advance.
Table-Valued Parameters is a new feature introduced in SQL SERVER 2008. In earlier versions of SQL SERVER it is not possible to pass a table variable in stored procedure as a parameter, but now in SQL SERVER 2008 we can use Table-Valued Parameter to send multiple rows of data to a stored procedure or a function without creating a temporary table or passing so many parameters.
You can read about it here
for more information about using it with ado
check this great article
SQL Server 2008 Table-Valued Parameters and C# Custom Iterators: A Match Made In Heaven!
well in the stored procedure you can use any many insert commands as you want in any table you want, as your question is not clear enough that i write the exact stored procedure you want, I'm writing an example.
use [databasename]
go
create procedure [dbo].[my_stored_procedure](#customerid int) as
begin
insert into [customerstable](customerid) values (#customerid)
insert into [someothertable](somefieldname1, somefieldname2) values(somefield1value, somefield2value)
insert into [someothertable2](somefieldname1, somefieldname2) values(somefield1value, somefield2value)
end