English 中文(简体)
图3 2000服务器动态变化数据库
原标题:Dynamically changing databases in SQL Server 2000

在工作上,我们拥有一些数据库,我们需要在同样的行动中这样做。 我想写一下1个方案,它将接管业务,并在整段开始时建立数据库(随后可效仿)。 我曾尝试过间谍——executesql(USE + @db_id),但这只是为这种储存程序的范围设置了银。 我并不真的想要掌握硬编码的数据库名称,因为我们需要在许多不同地方做类似的事情,如果我们增加另一个行,那就很难记住需要改变什么。

任何思想和思想;

Example:
DECLARE zdb_loop CURSOR FAST_FORWARD FOR SELECT distinct db_id from DBS order by db_id

OPEN zdb_loop FETCH NEXT FROM zdb_loop INTO @db_id

WHILE @@FETCH_STATUS = 0 BEGIN USE @db_id

--Do stuff against 3 or 4 different DBs

FETCH NEXT FROM zdb_loop INTO @db_id

出席情况

CLOSE zdb_loop DEALLOCATE zdb_loop

最佳回答

到目前为止,看起来像动态是做到这一点的唯一途径。 Pretty lame.

问题回答

http://www.databasejournal.com/features/mssql/article.php/3441031/SQL-Server-Undocumented-Stored-Procedures-spMSforeachtable-and-spMSforeachdb.htm” rel=“nofollow noreferer”_sp_MSforeachdb

This example will perform a database backup, then a "DBCC CHECKDB" against each database:

declare @cmd1 varchar(500)
declare @cmd2 varchar(500)
declare @cmd3 varchar(500)
set @cmd1 =
    if   ?   <>   tempdb   print   *** Processing DB ? ***   
set @cmd2 =  if   ?   <>   tempdb   backup database ? to disk=  c:	emp?.bak   
set @cmd3 =  if   ?   <>   tempdb   dbcc checkdb(?) 
exec sp_MSforeachdb @command1=@cmd1, 
                    @command2=@cmd2,
                    @command3=@cmd3




相关问题
Big Table Advice (SQL Server)

I m experiencing massive slowness when accessing one of my tables and I need some re-factoring advice. Sorry if this is not the correct area for this sort of thing. I m working on a project that aims ...

How do I define a work week in SQL Server 2000?

I need to split a report by work week, and our work week is Saturday through Friday. How would I convert an ISO week from DATEPART(WW, ) into a work week?

SQL Sever Management Studio for SQL Server 2000

We use mostly SQL Server 2005 but have a few SQL Server 2000 servers laying around. Is there a SQL Server Management Studio like application for SQL Server 2000? Thank you.

Sql server 2005 on sql server 2000

I want to ask is there any issues or risks involved in installation of SQL Server 2005 Enterprise Edition on SQL Server 2000 Enterprise Edition in production server? Please tell me the guidelines ...

LINQ, Skip, OrderBy, and SQL Server 2000

I m accessing a data context object that is auto-generated by using LINQ to SQL. The SQL database is a SQL Server 2000 box. The class I m working with is a SQL View. I have a statement that is similar ...

Select Top 5 records of every employee in SQL Server

I have the following issue, I have this query that select the latest 5 records created for an employee: SELECT TOP 5 p.value, p.record_date AS FECHA FROM employee_loan_movements p ...

热门标签