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 8319647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:23:32+00:00 2026-06-08T22:23:32+00:00

Essentially i need to run a quite large SQL script that wont run in

  • 0

Essentially i need to run a quite large SQL script that wont run in SSMS.

Using sqlcmd to input a .sql file however will simply seem to stop at first GO statement it reaches.

All it seems to run is:

USE [master]
GO

CMD writes: “Changed database context to ‘master'”

And then its idle, no cpu usage and bare minimal ram usage.

Even with minimized script just to create a new, empty DB, the result is the same.

the string i used would be like this:

sqlcmd -S 127.0.0.1 -U x -P x -i D:\x\f.sql 

it connects to the db just fine, however the included .sql script still wont run.

Setting errorlevel to 1 wont help, it still stops/halts, simply no message then.

  • 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-06-08T22:23:34+00:00Added an answer on June 8, 2026 at 10:23 pm

    I think you’ve got GO in the wrong place.

    I use sqlcmd for a unattended installs and have reproduced the issue and see what you mean.

    This is how I call scripts passing parameters:

    sqlcmd -S . -E -b -v Database="Test" -i "C:\temp\CreateDatabase.sql"
    

    This is the CreateDatabase.sql script file:

    :On Error exit
    --:Out null
    --:SetVar SQLCMDERRORLEVEL 18
    
    -- USE [master] GO -- with this line it fails, but its in the Master context already    
    
    DECLARE @Database varchar(64);
    DECLARE @Error int;
    DECLARE @Path varchar(256);
    DECLARE @BackUpPath varchar(256);
    
    SET @Database = '$(Database)';
    SET @Path = '';
    SET @BackUpPath = '';   
    
    IF @Path IS NULL OR RTrim(@Path) = ''
        SET @Path = (SELECT SUBSTRING(physical_name, 1, CHARINDEX('master.mdf', LOWER(physical_name)) - 1)
                    FROM master.sys.master_files
                    WHERE database_id = 1 AND file_id = 1);
    ELSE IF Right(@Path, 1) != ''
        SET @Path = @Path + '';
    
    IF EXISTS(SELECT [name] as [Database]
            FROM master.sys.databases
            WHERE [name] = @Database)
        RAISERROR ('Database already exists.', 18, 10); --  :Exit(SELECT 10)
    
    EXECUTE('CREATE DATABASE ' + @Database + ' ON PRIMARY 
            (NAME = ' + @Database + ', FILENAME = ''' + @Path + @Database + '.mdf'', FILEGROWTH = 1024KB)
            LOG ON
            (NAME = ' + @Database + '_log, FILENAME = ''' + @Path + @Database + '_log.ldf'', SIZE = 5MB,
        MAXSIZE = 25MB,
        FILEGROWTH = 5MB )
            COLLATE SQL_Latin1_General_CP1_CI_AI');
    
    IF @@Error != 0
        RAISERROR ('Failed to create database.', 18, 12);   --  :Exit(SELECT 2)
    

    So you dont need to use GO when creating a database.

    When creating the schema and populating your database I would suggest using SQL tools to export the script so you end up with scripts that look like this:

    USE [SpecificDatabase]
    
    
    /****** Object:  ForeignKey [FK_tblAppCustomers_tblCustomers]    Script Date: 11/23/2008 12:44:26 ******/
    IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_tblAppCustomers_tblCustomers]') AND parent_object_id = OBJECT_ID(N'[dbo].[tblAppCustomers]'))
    ALTER TABLE [dbo].[tblAppCustomers] DROP CONSTRAINT [FK_tblAppCustomers_tblCustomers]
    GO
    /****** Object:  ForeignKey [FK_tblAppSales_tblGS]    Script Date: 11/23/2008 12:44:26 ******/
    IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_tblAppSales_tblGS]') AND parent_object_id = OBJECT_ID(N'[dbo].[tblAppSales]'))
    ALTER TABLE [dbo].[tblAppSales] DROP CONSTRAINT [FK_tblAppSales_tblGS]
    GO
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a large filesystem that I need to traverse for errors. Each file
I'm working on a project that essentially creates files via a shell script using
I've got a bit of a problem. Essentially, I need to store a large
I'm writing a Java application that will run for a long time (essentially, it
I've run into a scenario where I essentially need to write the changes of
I need to run the following command: screen -dmS RealmD top Essentially invoking GNU
I've run into a limitation using boost exception and make_tuple with zero arguments. Essentially
I have a need to run a relatively large number of virtual machines on
So I essentially need to do this: String text = line1\n; text += line2\n;
I need to parse a simple statement (essentially a chain of function calls on

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.