GLOBAL
GLOBAL in SQL is a keyword used within the scope of variables in stored programs. It refers to system variables that are shared among all clients. These variables are accessible to all simultaneous sessions or processes in a database and remain persistent throughout the SQL server’s runtime. Changes to GLOBAL variables affect the operation of the server and all subsequent connections.
Example
Output
Explanation
In the example code, a database called testDB
is created and used. A table Employees
is then created in testDB
, followed by an insertion of a record into it.
Then the session variable max_connections
is set to 200 at a global level with SET GLOBAL max_connections = 200;
.
The SHOW GLOBAL VARIABLES LIKE 'max_connections';
command is used to display the globally set variable for ‘max_connections’, which displays the max_connections
value as 200 in the output as proof of the successful execution.
Example
Output
Explanation
In the example, the GLOBAL keyword is implied with the double colons (::
) before fn_helpcollations()
. This function is a global function and it fetches a list of all collations and their properties in SQL Server. The WHERE clause filters for a specific collation 'Latin1_General_CI_AI'
, and the output is a record of this collation and its properties.
Example
Output
No output produced for table creation. Executing SELECT statement on session_addresses would result in:
USER_ID | ADDRESS |
---|
Explanation
GLOBAL temporary tables are visible to all sessions, but the data is session-specific. The statement above creates a global temporary table called session_addresses
, structured similarly to the addresses
table but initially empty as denoted by WHERE 1 = 0
. The SELECT * FROM session_addresses;
statement retrieves data from the session_addresses
table, but as the table is initially empty, no rows are returned.