Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Administration
 compile sql files.....

Author  Topic 

devd
Starting Member

1 Post

Posted - 2012-07-24 : 15:05:51
Hi
Is there any way to compile the sql files and check for syntax errors through cmd.

Example :
-------------------------------------
Correct Syntax :

INSERT INTO Persons VALUES ('Nilsen')

-------------------------------------
Wrong Syntax :
INSERT INTO Persons VALUE ("Nilsen")

Wrong syntax at values and "

Second Question :

Can we compile the sql file (Syntax error) with out executing the sql scripts (insertion of data)?

robvolk
Most Valuable Yak

15732 Posts

Posted - 2012-07-24 : 15:11:13
If you place SET FMTONLY ON at the beginning of your script it will only parse the text.
Go to Top of Page

komkrit
Yak Posting Veteran

60 Posts

Posted - 2012-07-25 : 13:45:50
To devd, and additional to robvolk

For my quick tip, I usually use "Parse" button in SSMS (locate at toolbars)
or Menu "Query" --> "Parse"
For shortcut, use Ctrl-F5
It won't execute, but only check syntax. Safe to your data.

Please noted that, "Parse" is just check syntax, but not object validation.
In the case object does not exists, parse won't notified.
I usually use "Ctrl-L" or "Display Estimated Execution Plan" button to check syntax and validate object without executing.
Also safe to data.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Komkrit Yensirikul
Currently be a DBA in worldwide hotel reservation. Experienced in top leading banking environment.
Go to Top of Page
   

- Advertisement -