How to obtain the database name of the current SQL _ MySQL

Source: Internet
Author: User
Here are a few questions about SQLSERVER (server-side scripting): (1) how to obtain the current database name using SQL statements in SQLSERVER? (2) how to define a global variable instead of a local variable, because here I define a loop, in this loop, you can add fields to a temporary table and insert data to the temporary table. But here are a few questions about SQL SERVER (SERVER-side scripting ):
(1) how to obtain the current database name using SQL statements in SQL SERVER?
(2) how to define a global variable instead of a local variable, because I have defined
In a loop, a field is added to a temporary table and data is inserted to the temporary table.
. However, these two operations must be placed in different batches (separated by GO statements ).
The variable parameter that controls the loop does not work, because the variable parameter can only be in one
It takes effect in batches and will be redefined in the next batch. A headache! Can it be defined?
Global variable to make it work in all batches?

These two problems are not universal, but the ideas and methods for solving these two problems are universal. Therefore, I will discuss these two problems.
(1) First of all, the current DataBase must use the system stored procedure, which is very certain. I naturally thought of executing sp_who to list all information about the existing system process, when I see Runnable and Slepping, it must be runnable. when I think of his spid, I think there is a global variable @ SPID in the system. I 'd like to give it a try first, sp_who @ spid haha successfully solves this problem. you must be familiar with the system's stored procedures and global system variables, and be good at observing and thinking.
(2) As for the second problem, it is purely a problem of t-SQL programming ideas. first, I do not agree to use a rule to judge two stored procedures, because this is not consistent with the t-SQL programming specification, but since the problem has come out, we have to find a solution. we know that it is impossible to share data in two batches, so I thought of the cursor, and finally passed the test and succeeded.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.