插入数据时如何在mysql中设置表名

插入数据时如何在mysql中设置表名

问题描述:

我想在mysql数据库的表中插入数据,但问题是


我正在使用存储过程插入数据


我想分配表名称,如

i want insert the data in table in mysql database but problem is that


i am using the store procedure for insert data


i want to assign the table name like

DROP PROCEDURE IF EXISTS `sp_insert_data` $$
CREATE DEFINER=`root`@`%` PROCEDURE `sp_insert_data`(
in temp_table_name varchar(40))
 

how to write insert statement

like 
insert into temp_table_name values();


becauese i have 450 tables and i want whatever string in temp_table_name  i want to insert in that table...

pls fast reply

创建 DEFINER =`root` @`%`程序`sp_insert_data`( in temp_table_name varchar ( 40 )) 如何如何编写插入语句 喜欢 插入 插入 temp_table_name (); 因为我有 450 and ,我想要中的任何字符串/span> temp_table_name我想要插入 插入 插入表格 ... 请快速回复
CREATE DEFINER=`root`@`%` PROCEDURE `sp_insert_data`( in temp_table_name varchar(40)) how to write insert statement like insert into temp_table_name values(); becauese i have 450 tables and i want whatever string in temp_table_name i want to insert in that table... pls fast reply


这是一个非常疯狂的想法.如果要即时生成SQL,则使用存储的proc没有意义.在SQL Server中,您可以构建一个SQL字符串并在其上调用EXEC,如果MySQL允许这样做,则这是唯一可行的方法.除非所有表的变量​​数都相同,否则那里将有问题,而且这意味着您没有指定要插入的列,这也是一个坏主意.

这是一场噩梦,不要这样做.如果您有450个表,则您有一个大项目,该项目比这要好得多.
This is a really insane idea. If you want to generate SQL on the fly to this degree, there''s no point using stored procs. In SQL Server, you can build a SQL string and call EXEC on it, if MySQL allows this, it''s the only way this would be possible. Unless all your tables have the same number of variables, you are going to have issues there, plus it means you''re not specifying what columns you are inserting in, which is also a bad idea.

This is a nightmare, don''t do it. If you have 450 tables, you have a big project, which deserves far better code than this.