久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在 SQL 中將數(shù)據(jù)庫名稱設(shè)置為變量

Setting database name as a variable in SQL(在 SQL 中將數(shù)據(jù)庫名稱設(shè)置為變量)
本文介紹了在 SQL 中將數(shù)據(jù)庫名稱設(shè)置為變量的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

限時(shí)送ChatGPT賬號(hào)..

目前,我正在根據(jù)一些業(yè)務(wù)規(guī)則在一個(gè)數(shù)據(jù)庫到另一個(gè)數(shù)據(jù)庫之間進(jìn)行一些數(shù)據(jù)遷移.

currently, I'm doing a bit of a data migration between one db to another based on some business rules.

我有一個(gè)巨大的腳本,我正在編寫它,我在其中多次引用了兩個(gè)數(shù)據(jù)庫.問題是這種數(shù)據(jù)遷移目前正在開發(fā)中,在某些時(shí)候,我想在生產(chǎn)環(huán)境中使用兩個(gè)不同的數(shù)據(jù)庫進(jìn)行遷移.

I have this huge script that I'm writing where I'm referencing both databases a lot of times. The problem is that this data migration is currently in development, at some point I am going to want to have to do it in production with two different databases.

而不是像這樣直接引用數(shù)據(jù)庫名稱

Instead of referencing the database name directly like so

Insert Into Database2.dbo.Table1    
Select * from Database1.dbo.Table1

我想以某種方式在腳本開始時(shí)引用數(shù)據(jù)庫.這樣我就可以在更改數(shù)據(jù)庫時(shí)只更改一個(gè)變量.

I would like to somehow just reference the database at the start of the script. So that I can just change the one variable when I change databases.

這可能嗎?

推薦答案

使用 SQLCMD變量:

:setvar dbfrom database1
:setvar dbto database2

Insert into [$(dbto)].dbo.Table1
select * from [$(dbfrom)].dbo.Table2;

此語法適用于 sqlcmd.exe(來自腳本)以及 Management Studio,請(qǐng)參閱 使用查詢編輯器編輯 SQLCMD 腳本.腳本還允許您從命令行設(shè)置變量:

This syntax works in sqlcmd.exe (from scripts), as well as in Management Studio, see Editing SQLCMD Scripts with Query Editor. Scripting also allows you to set the variables from the command line:

sqlcmd /E /S server /i script.sql /v dbfrom=database1 /v dbto=database2

我還有一個(gè)庫,允許您使用來自應(yīng)用程序的 sqlcmd 變量和腳本作為 Google 代碼的來源.

I also have a library that allows you to use sqlcmd variables and scripts from applications available as source on Google Code.

這篇關(guān)于在 SQL 中將數(shù)據(jù)庫名稱設(shè)置為變量的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

What SQL Server Datatype Should I Use To Store A Byte[](我應(yīng)該使用什么 SQL Server 數(shù)據(jù)類型來存儲(chǔ)字節(jié) [])
Interpreting type codes in sys.objects in SQL Server(解釋 SQL Server 中 sys.objects 中的類型代碼)
Typeorm Does not return all data(Typeorm 不返回所有數(shù)據(jù))
Typeorm .loadRelationCountAndMap returns zeros(Typeorm .loadRelationCountAndMap 返回零)
How to convert #39;2016-07-01 01:12:22 PM#39; to #39;2016-07-01 13:12:22#39; hour format?(如何將“2016-07-01 01:12:22 PM轉(zhuǎn)換為“2016-07-01 13:12:22小時(shí)格式?)
MS SQL: Should ISDATE() Return quot;1quot; when Cannot Cast as Date?(MS SQL:ISDATE() 是否應(yīng)該返回“1?什么時(shí)候不能投射為日期?)
主站蜘蛛池模板: 中文字幕日韩欧美 | 欧美综合精品 | 久久久久久免费看 | 国产欧美在线一区二区 | 三级av免费 | 亚洲欧美一区二区三区在线 | 精品国产鲁一鲁一区二区张丽 | 日韩视频在线观看 | 中文字幕一区二区三区四区 | 激情福利视频 | 成人免费精品视频 | 成人在线精品视频 | 亚洲在线观看视频 | 亚洲精品无 | 九九热精品在线 | 欧美二区在线 | av网站免费在线观看 | 黄色在线观看网址 | 红色av社区 | 国产一区二区精品在线 | 色婷婷一区二区三区四区 | 超碰成人免费观看 | 国产黄色小视频 | 国产精品一区视频 | 亚洲综合区 | 欧美最猛性xxxxx亚洲精品 | 在线一区观看 | 亚洲精品www久久久久久广东 | 久久在视频 | 成人小视频在线观看 | 国产高清久久久 | 中文字幕日韩欧美 | 国产精品免费一区二区三区四区 | 少妇午夜一级艳片欧美精品 | 国产一二三区免费视频 | 观看av| 亚洲综合一区二区三区 | 欧美韩一区二区三区 | 亚洲444eee在线观看 | 国产二区视频 | 免费激情网站 |