Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7629285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:47:59+00:00 2026-05-31T05:47:59+00:00

We have several SQL scripts which are generated from an Entity Model. They need

  • 0

We have several SQL scripts which are generated from an Entity Model. They need to be run in a specific order. Additionally there are several filling scripts which insert test data into the database.

Currently I need to open each script in Visual Studio and execute them in the correct order by clicking Execute (ctrl shift E).

Is there a way to create a script like Master.sql that contains includes like this:

BEGIN TRANSACTION

ImportOrInclude myDB1.sql
ImportOrInclude myDB2.sql
...

COMMIT

This is only required to run from Visual Studio and will not be part of the application itself.

How can this be done?

EDIT 1

I’ve found that there is something called SQLCMD Scripts which can import SQL files:
http://msdn.microsoft.com/en-us/library/aa833281%28v=vs.80%29.aspx

But my question is then how to get the directory path of the current solution into the :r command.

EDIT 2

So I figured out how to do it, not perfectly, but it works. The downside is that the $(SolutionDir) is not loaded from the Visual Studio variables, so you need to set it up manually. This code is meant to be run in Visual Studio:

-- turn on in menu: Data -> Transact SQL editor -> SQL CMD mode
-- set this to path where the .sln file is.
:setvar SolutionDir C:\_work\projectname\

:!! echo $(SolutionDir)Maa.EntityModel.All\DbWEntityModel.edmx.sql 
:r $(SolutionDir)Maa.EntityModel.All\DbWEntityModel.edmx.sql 
go

:!! echo $(SolutionDir)Maa.EntityModel.All\DblQEntityModel.edmx.sql 
:r $(SolutionDir)Maa.EntityModel.All\DbQEntityModel.edmx.sql 
go
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T05:48:00+00:00Added an answer on May 31, 2026 at 5:48 am

    Use sqlcmd utility.

    Extract you might find interesting:

    -i input_file[,input_file2...]
    

    Identifies the file that contains a batch of SQL statements or stored procedures. Multiple files may be specified that will be read and processed in order. Do not use any spaces between file names. sqlcmd will first check to see whether all the specified files exist. If one or more files do not exist, sqlcmd will exit.

    Example:

    sqlcmd -dDataBaseName -E -Stcp:ServerName\instancename -imaster.sql
    

    Master.Sql:

    :r file1.sql
    :r file2.sql
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have several SQL Server 2000 databases (I know, we need to upgrade) that
I have several Oracle queries that perform well when run through SQL*PLUS. However when
I have a SQL Server database which is shared between several ASP.NET (VB.NET) websites,
I have to copy data from several tables from SQL Server to Oracle. The
I have created several SQL database change scripts, and placed them in a folder.
In my application I'm using Entity Framework 4.0 Model First. I have several tables
I have two databases: DBTarget and DBTest . I've run several custom scripts on
I have several sql queries that I simply want to fire at the database.
I have several assemblies for SQL Server 2005. If invalid data is entered to
I have several instances where that a section of legacy sql statements is based

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.