English 中文(简体)
在MySQL 文本中建立当前数据库
原标题:Set Current Database in MySQL Script

我有一份需要用大约30个数据库操作的MySQL文件。 这里指:

ALTER TABLE <whatever_database>.`tblusers` ADD COLUMN `availability` ...

ALTER TABLE <whatever_database>.`tblusers` ADD COLUMN `reliability` INTEGER ...

这一文字中还有许多条线,我希望在目前数据库中将其自动化,以便更新。 我拿着这份清单,用 cur子 lo倒,但这里我 trouble忙:

当在曲线某一特定数据库上安装一米时,该数据库的名称是变数。 我只能说ALTER TABLE好奇马,tblusers,因为文字抱怨说,没有数据库的名称是好奇马(包含我喜欢操作的数据库名称的变量名称)。 我早就能够为此而努力,利用参数编制和执行一项声明:

SET @curschema = curschema;
SET @query = NULL;
SET @email = emailAddress;
SET @pass = pass;
SET @statement = CONCAT( SELECT userid INTO @query FROM  , @curschema,  .tbluser 
PREPARE stmt FROM @statement;
EXECUTE stmt;

问题在于,建立可起诉的扼杀(如上所述)将成为一个极为棘手的任务,我必须操作数十条法典。 我希望,我能为行动建立现有数据库,然后再重新建立数据库,每份通行证都可以操作,这样我通用的发言就可以:

(我开始发言)

SET DATABASE数据库0——(通过数据库29)

- 附有数据库0的报表......

ALTER TABLE `tblusers` ADD COLUMN `availability` TINYINT(1) UNSIGNED ...

ALTER TABLE `tblusers` ADD COLUMN `reliability` INTEGER UNSIGNED NOT ...

(我的休息时间)

是否存在这种指挥系统,以建立目前可开展哪些行动的数据库? 如果不存在这种指挥,我的任务是否容易完成? 我估计,在目前这一关头,在所有数据库名称上找到/替换比照将我的整个文字档案重新编成可执行/参数化的说明更为容易。

感谢!

最佳回答

http://dev.mysql.com/doc/refman/5.1/en/use.html

USE db_name

The USE db_name statement tells MySQL to use the db_name database as the default (current) database for subsequent statements. The database remains the default until the end of the session or another USE statement is issued.

例:

USE db1;
SELECT COUNT(*) FROM mytable;   # selects from db1.mytable
USE db2;
SELECT COUNT(*) FROM mytable;   # selects from db2.mytable
问题回答

暂无回答




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签