开发者

Cannot use GO statement when creating tables in this simple use case

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 nva开发者_开发百科rchar(400),
telefono int,
nit int
);


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.


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


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.


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)


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜