如何解决如何在T-SQL和SQLCMD脚本中连接常量字符串?
我仍在学习T-SQL和SQLCMD脚本的基础知识。
是否可以将一个字符串(作为父文件夹路径)与其他字符串(作为子文件夹路径)连接起来。
-- Global variables
DECALRE @PARENT_PATH NVARCHAR(256);
SET @PARENT_PATH = 'parent_path'; -- OK,works but I've seen some string ending with '%'..
-- Some steps to check if the database already exists and deals with it
-- ..
-- Database creation
CREATE DATABASE [MyDatabase]
ON
(NAME = "MyDatabase",FILENAME = @PARENT_PATH + "MyDatabase.mdf") -- How to do it? I know the CONCAT() function,but doesn't seem to work. Should I define and set another intermediate variable,instead of concatenating it directly?
LOG ON
(Name = "MyDatabase_log",FILENAME = @PARENT_PATH + "MyDatabase_log.ldf")
GO
-- Table creation
-- ..
-- Executes stored procedures scripts (SQLCMD) where each stored procedure is written in a separate file
:setvar STORED_PROCEUDRE_PATH @PARENT_PATH + "Stored Procedures\" -- How to do it?
:r $(STORED_PROCEUDRE_PATH)spStoreProcedureName.sql
-- By the way,still need to get used to the following SQLCMD loop syntax
-- FOR %%Script IN ($(STRORE_PROCEDURE_PATH)*.sql) DO sqlcmd /S servername /d MyDatabase -E -i" %%Script"
-- PAUSE
我以前已经看过一些线程,但是还没有找到解决方案。
感谢您的见解!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。