James (eh****@hotmail.com) writes:
I'm trying to execute a file containing few SQL statements.
CREATE VIEW test1 AS SELECT * FROM table1;
CREATE VIEW test2 AS SELECT * FROM table2;
The standard SQL way is to end a statement with semi-colon.
But doing that,it doesn't work in SQL Server.
After changing ";" to "GO", it works fine.
Is there anyway we can stick to ";" to indicate the end of statement.
I don't want to create scripts which works only in SQL Server.
This is not legal T-SQL:
CREATE VIEW test1 AS SELECT * FROM table1;
go
CREATE VIEW test2 AS SELECT * FROM table2;
go
For some explicable reason ; is not permitted here. (Probably because
CREATE VIEW must be alone in a batch.
However, if you change the batch separator to with the -c option as
Simon Hayes suggested, this works:
CREATE VIEW test1 AS SELECT * FROM table1
;
CREATE VIEW test2 AS SELECT * FROM table2
;
And it still legal in ANSI-compliant engines.
Since the batch-separator must be alone on a line, this solution
can work decently. Of course if a developer for some reason puts a
lone semicolon in the middle of a stored procedure, he effectively
splits that procedure in two.
--
Erland Sommarskog, SQL Server MVP,
so****@algonet.se
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp