0

I'm trying to run this SQL script but it's not working. It says there is an error near the GO text.

create table rubro
(
id_rubro int primary key,
nombre_rubro nvarchar(150)
);
GO
create table cliente
(
id_cliente int primary key,
direccion nvarchar(400),
telefono int,
nit int
);
Sergio Tapia
  • 40,006
  • 76
  • 183
  • 254
  • 1
    Can you post the error? I can't see why GO would be a problem. The more likely problem is that the table already exists. – spinon Jul 13 '10 at 19:32

5 Answers5

4

You may have some other text causing the error. When I copy and paste the same script into the Query Analyzer, it creates the 2 tables just fine.

Jose Basilio
  • 50,714
  • 13
  • 121
  • 117
  • 1
    I'm using this statement inside of Visual Studio 2010. – Sergio Tapia Jul 13 '10 at 19:28
  • 1
    @Sergio Tapia: **GO** is **NOT** a SQL keyword - it's a command delimiter which works only in SQL Srv Mgmt Studio. Do not use **GO** in your normal SQL scripts - typically it's not necessary anyway... – marc_s Jul 13 '10 at 19:30
  • +1 didn't know that. How could I test this if I don't have Srv Mgmt Studio? – Sergio Tapia Jul 13 '10 at 19:32
  • @Sergio Tapia: just remove the two lines with the "GO" statements - should work just fine without the GO, too – marc_s Jul 13 '10 at 19:34
2

That runs just fine, are you sure you are using SQL Server? Perhaps you are in SQLCMD mode or you have hidden characters. Paste it into notepad++ or editplus and look for hidden characters

SQLMenace
  • 132,095
  • 25
  • 206
  • 225
0

What does the error say? Maybe the table already exists.

Also if you want the id field to increment automatically, the script will not do that.

Another possibility is that you do not have the rights to create a table.

HLGEM
  • 94,695
  • 15
  • 113
  • 186
0

The "GO" batch separator keyword is actually used by SQL Management Studio itself, so that it knows where to terminate the batches it is sending to the server, and it is not passed to SQL server. You can even change the keyword in Management Studio, should you so desire.

Note that certain statements like CREATE FUNCTION have to be the first statement in a batch. To execute such a thing in an environment outside SSMS or SQLCMD, you will need to execute them separately (i.e. implement your own batch separator)

Cade Roux
  • 88,164
  • 40
  • 182
  • 265
0

GO is not a legal T-SQL statement. See my answer to this question.

Community
  • 1
  • 1
Christian Hayter
  • 30,581
  • 6
  • 72
  • 99