About 24,800,000 results
Open links in new tab
  1. sql - How to switch database context to newly created database

    How do I switch to a SQL Server Server Database that will exist after another command?

  2. sql server - Switching between databases with dynamic SQL - Database

    Oct 21, 2015 · Is there a way to do this which will correctly switch between databases? @proc = 'ssc.sys.sp_executesql' @sql NVARCHAR(MAX), @dbname NVARCHAR(MAX) = NULL. /* PURPOSE. Runs SQL statements in this database or another database. You can use parameters. TEST. EXEC dbo.Infrastructure_ExecuteSQL 'SELECT @@version, db_name();', 'master'; REVISION HISTORY.

  3. How to change default database in SQL Server without using MS SQL

    With the MSSQL queries below, you can change database on sqlcmd: USE testdb GO Then, you can check the currently used database: SELECT DB_NAME() GO testdb. Then, you can show all the existed databases: SELECT name FROM master.sys.databases GO …

  4. sql server - Switching from one database to another within the …

    Jan 28, 2015 · The goal is switch to the new database (USE NewDatabase) so that the other part of my script (DBCC CHECKDB) can run. This script checks the integrity of the database and saves the results to a temp table.

  5. How to change the current database in an SQL Query window in …

    Feb 13, 2018 · Use a new connection to connect to a different database. I've considered turning on SQL CMD mode and using the :CONNECT command, but I don't want to connect to a different database server, just change the database.

  6. ALTER DATABASE (Transact-SQL) - SQL Server | Microsoft Learn

    Mar 10, 2025 · Use this statement to change the name of a database, change the edition and service objective of the database, join or remove the database to or from an elastic pool, set database options, add or remove the database as a secondary in a geo-replication relationship, and set the database compatibility level.

  7. How to Dynamically change the database using TSQL

    Sep 4, 2017 · If the ultimate goal is to execute some other dynamic SQL inside the chosen database, this is easy enough: DECLARE @db sysname = N'db1'; DECLARE @exec nvarchar(max) = QUOTENAME(@db) + N'.sys.sp_executesql', @sql nvarchar(max) = N'SELECT DB_NAME();'; EXEC @exec @sql; If you need to pass parameters, no problem:

  8. Switch Databases - SQLServerCentral

    Jul 13, 2001 · -- Description: -- This script is used to drop the old database from yesterday's load. -- It is then used to switch the active database to become tomorrow's old DB, -- and then to switch...

  9. SQL ALTER DATABASE - W3Schools

    SQL ALTER DATABASE is an essential statement to modify the properties of an existing database in a Relational Database Management System (RDBMS). This statement is helpful if you want to rename a database, change its composition, or modify file properties.

  10. SQL - SELECT Database, USE Statement - Online Tutorials Library

    To work with a database in SQL, we need to first select the database we want to work with. After selecting the database, we can perform various operations on it such as creating tables, inserting data, updating data, and deleting data. The SQL USE DATABASE statement is used to select a database from a list of databases available in the system.

  11. Some results have been removed