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

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

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

問題描述

限時送ChatGPT賬號..

目前,我正在根據(jù)一些業(yè)務(wù)規(guī)則在一個數(shù)據(jù)庫到另一個數(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.

我有一個巨大的腳本,我正在編寫它,我在其中多次引用了兩個數(shù)據(jù)庫.問題是這種數(shù)據(jù)遷移目前正在開發(fā)中,在某些時候,我想在生產(chǎn)環(huán)境中使用兩個不同的數(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ù)據(jù)庫.這樣我就可以在更改數(shù)據(jù)庫時只更改一個變量.

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,請參閱 使用查詢編輯器編輯 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

我還有一個庫,允許您使用來自應(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è)置為變量的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

What SQL Server Datatype Should I Use To Store A Byte[](我應(yīng)該使用什么 SQL Server 數(shù)據(jù)類型來存儲字節(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小時格式?)
MS SQL: Should ISDATE() Return quot;1quot; when Cannot Cast as Date?(MS SQL:ISDATE() 是否應(yīng)該返回“1?什么時候不能投射為日期?)
主站蜘蛛池模板: 精品久久精品 | 在线日韩欧美 | 欧美一区不卡 | 欧美韩一区二区三区 | 美女视频黄的免费 | 精品1区2区| 久久99久久98精品免观看软件 | 国产在线观看不卡一区二区三区 | 国产精品视频网站 | 综合久久综合久久 | 精品伦精品一区二区三区视频 | 婷婷久久五月 | 久久香蕉精品视频 | 蜜桃视频在线观看免费视频网站www | 天天操夜夜爽 | 免费观看成人性生生活片 | 在线视频一区二区 | 国产一区欧美一区 | 色本道| 国产一区二区在线免费视频 | 亚洲电影专区 | 精品国产一区久久 | 亚洲精品毛片av | 一区中文字幕 | 日韩在线一区二区三区 | 大伊人久久 | 成人乱人乱一区二区三区软件 | 国产a区 | 蜜桃av鲁一鲁一鲁一鲁 | 亚洲一区二区电影在线观看 | 爱爱视频网 | 国产精品午夜电影 | 中日韩av | 亚洲激情在线视频 | 欧美日韩在线一区二区 | 伊人伊人网| 久久高清国产 | 色婷婷综合网站 | 久久高清精品 | 成人啊啊啊 | 成人性视频在线播放 |