| > In MS SQL Server, a CREATE PROCEDURE statement cannot appear halfway through a batch of SQL statements. There's no good reason for this, it's just an arbitrary limitation. It means that extra manual steps are often required to execute a large batch of SQL. Manual steps increase risk and reduce efficiency. It's been a while, but I am pretty sure all you have to do is put GO before/after the CREATE PROCEDURE. I'm absolutely positive there's some way around it, because I've run many, many such scripts on SQL Server without manual intervention. EDIT: Yes, I just fired up a VM and ran this and got the expected results with no errors. CREATE DATABASE HackerNews; CREATE TABLE dbo.Test (id int IDENTITY(1, 1), name varchar(20)); GO INSERT INTO dbo.Test (name) VALUES ('Amezarak'); GO CREATE PROCEDURE dbo.sp_QueryTest
AS
SELECT * FROM dbo.Test; GO EXEC dbo.sp_QueryTest In my personal opinion, MSSQL (including the tooling around it) is awesome and possibly one of Microsoft's best products. I actually regret not getting to use it anymore since a) my current job doesn't use it and b) I'm not shelling out for a license for my side projects. Postgres is definitely my next pick, though, and both are miles ahead of MySQL. I understand that MySQL is "good enough" for most people, but it's always painful going back to it and inevitably remembering almost all my favorite features don't exist. I'm stuck with it on a side project and it's frustrating. |