Incorrect Syntax near GO

  • When I executes Database creation sqlscript programmatically through .NET. It gives "Incorrect syntax near 'GO'.". My sql script is

    USE [master]

    GO

    /****** Object: Database [test] Script Date: 04/06/2010 14:30:46 ******/

    CREATE DATABASE [test] ON PRIMARY

    ( NAME = N'test', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\test.mdf' , SIZE = 2048KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )

    LOG ON

    ( NAME = N'test_log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\test_log.ldf' , SIZE = 1024KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)

    GO

    ALTER DATABASE [test] SET COMPATIBILITY_LEVEL = 100

    GO

    IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))

    begin

    EXEC [test].[dbo].[sp_fulltext_database] @action = 'enable'

    end

    GO

    ALTER DATABASE [test] SET ANSI_NULL_DEFAULT OFF

    GO

    ALTER DATABASE [test] SET ANSI_NULLS OFF

    GO

    ALTER DATABASE [test] SET ANSI_PADDING OFF

    GO

    ALTER DATABASE [test] SET ANSI_WARNINGS OFF

    GO

    ALTER DATABASE [test] SET ARITHABORT OFF

    GO

    ALTER DATABASE [test] SET AUTO_CLOSE OFF

    GO

    ALTER DATABASE [test] SET AUTO_CREATE_STATISTICS ON

    GO

    ALTER DATABASE [test] SET AUTO_SHRINK OFF

    GO

    ALTER DATABASE [test] SET AUTO_UPDATE_STATISTICS ON

    GO

    ALTER DATABASE [test] SET CURSOR_CLOSE_ON_COMMIT OFF

    GO

    ALTER DATABASE [test] SET CURSOR_DEFAULT GLOBAL

    GO

    ALTER DATABASE [test] SET CONCAT_NULL_YIELDS_NULL OFF

    GO

    ALTER DATABASE [test] SET NUMERIC_ROUNDABORT OFF

    GO

    ALTER DATABASE [test] SET QUOTED_IDENTIFIER OFF

    GO

    ALTER DATABASE [test] SET RECURSIVE_TRIGGERS OFF

    GO

    ALTER DATABASE [test] SET DISABLE_BROKER

    GO

    ALTER DATABASE [test] SET AUTO_UPDATE_STATISTICS_ASYNC OFF

    GO

    ALTER DATABASE [test] SET DATE_CORRELATION_OPTIMIZATION OFF

    GO

    ALTER DATABASE [test] SET TRUSTWORTHY OFF

    GO

    ALTER DATABASE [test] SET ALLOW_SNAPSHOT_ISOLATION OFF

    GO

    ALTER DATABASE [test] SET PARAMETERIZATION SIMPLE

    GO

    ALTER DATABASE [test] SET READ_COMMITTED_SNAPSHOT OFF

    GO

    ALTER DATABASE [test] SET HONOR_BROKER_PRIORITY OFF

    GO

    ALTER DATABASE [test] SET READ_WRITE

    GO

    ALTER DATABASE [test] SET RECOVERY SIMPLE

    GO

    ALTER DATABASE [test] SET MULTI_USER

    GO

    ALTER DATABASE [test] SET PAGE_VERIFY CHECKSUM

    GO

    ALTER DATABASE [test] SET DB_CHAINING OFF

    GO

    Please help me

  • GO as a command means nothing to Sqlserver. It is used by management studio to break the commands into separate batches. You need to send you commands in one block (without GO) or separate statements.



    Clear Sky SQL
    My Blog[/url]

  • So how can I create scripts without Go using sql management studio

  • You dont.

    You need to send the commands batches ( ie each GO block) separately to SQLServer.



    Clear Sky SQL
    My Blog[/url]

  • One doubt mate, are u trying to run this piece of code in SSMS 2005 or SSMS 2008?

  • Its SSMS 2008.

  • For SQL Server 2005, the compatiblity level can maximum be 90 and there is no command like HONOR_BROKER_PRIORITY

    I tried this code in both SQL 2005 and 2008. i got error for the 2 properties i said above for 2005 and in 2008 it got compiled well...

  • So why state, "sqlscript programmatically through .NET" ?



    Clear Sky SQL
    My Blog[/url]

  • Hmmm..

    Tel me if u did this:

    1. You Right-click on the database, "Create To" to a new SQL Server Window

    2. SAve this script as .sql file

    3. And now u are trying to run this .sql file using some .Net code.

    Is that right man? or are u trying to run the script from SSMS itself??

  • Yes you are right. I am doing these steps.

  • Is your .Net Code executing the .sql thro sqlcmd/isql or is it reading the whole database creation query into a string and then executing the string using ExecuteQuery ?

  • Amit,

    Please write down what you are doing. Type "I execute this in SSMS 2008 and get an error" or "I run this through .NET" and don't have people guessing about the issue.

    We are more than happy to help, but it doesn't appear you have been clear about how you are receiving the error.

  • amit.jaura 81056 (4/6/2010)


    So how can I create scripts without Go using sql management studio

    Tools -> Options

    SQL Server Object Explorer -> Scripting

    "Delimit individual statements" ... set this to 'False'

Viewing 13 posts - 1 through 12 (of 12 total)

You must be logged in to reply to this topic. Login to reply