Recently I have been working with a SQL Server database and I was trying to create some triggers for some tables using SQuirreL SQL Client and for some reason I was unable to get rid of the following pesky error message:
"Error: 'CREATE TRIGGER' must be the first statement in a query batch.
SQLState: S0001
ErrorCode: 111"
The query I was attempting to execute was the following (I started out with a really simple trigger to make sure the syntax was correct):
CREATE TRIGGER meeting_overlap on adhoc_meeting
FOR INSERT
AS
DECLARE
#myvar INT
When I attempted to execute my exact same query in Microsoft SQL Server Management Studio Express it executed fine. My question is: has anyone else run into similar problems using SQuirreL SQL Client and if so, what did you do to get rid of this error?
EDIT:
I am using SQuirrel SQL v2.6.8 with the Microsoft SQL Server JDBC Driver 2.0 and I am connecting to SQL Server 2005.
I was having the same problem. After some Googling, I found this article:
http://vsingleton.blogspot.com/2009/04/error-create-view-must-be-first.html
In short, wrap exec('') around your create trigger statement. In addition, any single quotes (') you have in the trigger statement need to be changed double single quotes ('').
Usually you get that error when attempting to run multiple statements in the same batch that are not allowed to be anything but the first statement in a batch. You may need a GO in between them. GO is not a SQL command but really a directive to the client tool to separate batches of commands.
I couldn't replicate this on SQuirrel SQL v2.6.8 using v1.2.2 of the jTDS jbdc driver against SQL 2005 SP3 (developer edition).
Related
I have seen a lot of links on the internet regarding this but I am in a little fix as to how can we connect to a SQL Server database and insert some records to it using a shell script.
I want to be able to create a function which accepts the values for the row, creates an sql statement and then executes it to insert data into the SQL Server Database. I know that there is Microsoft ODBC for this but I am not sure as to how we can create the said function with it.
I have a problem connecting AS400 (V7R3M0) with SQL Server 2017 via ODBC Link Server. It is very slow.
SELECT *
FROM AS400.CATALOG.LIBDTA.TABLE1
WHERE ...
How to fix this? If you don't want to use OPENQUERY
Thanks
How to fix this? If you don't want to use OPENQUERY
You can't...MS in their infinite wisdom decided that the way a (non-MS?) linked server would work is that the entire table would be pulled back and the where performed locally.
If you use OPENQUERY, then the SQL is sent to the linked server, executed and only the results are returned.
I supposed if your WHERE clause is static, you could set up a view on the IBM i side, then just query the view. But those use cases are few and far between.
I am having trobule trying to copy a database using sql server management studio.
The script which was generated using the wizard throws the following error when I try to run it to create the new database;
Reference to database and/or server name in
'databasename'.dbo.sp_fulltext_database' is not supported in this
version of SQL server
This is despite generating the script using the correct version number and a couple of other ones to test.
I am following the steps in the following post
http://johanbenjaminsson.com/how-to-make-a-copy-of-an-umbraco-database/
Steps are not the exact same as the post is from a while back but the process is the same.
The line that seems to have the error is the following
EXEC [<databasename>].[dbo].[sp_fulltext_database| #action = 'enable'
Struggling with this so any advice would be great.
I don't have the management studio installed and cannot install the express version as there seems to be a problem with my computer set up.
However I have VS2013 and I can open up query windows.
I created Indexes but then since then I have added a lot of new data. Is there some way I can update statistics for my SQL Server 2012 database from the SQL Script command line?
Try EXEC SP_updatestats to update all database statistics.
You can access the SQL command line using the tool sqlcmd that is installed as part of SQL 2012.
Here's a link to the update statistics command that you'll need to put together and execute.
http://technet.microsoft.com/en-us/library/ms187348.aspx
You can always create a script for the update statistics command, then execute that.
If you have both SQL and SQL Express installed, please make sure that you are connecting to the correct instance of SQL Server. the machine name alone or localhost should take you to the full sql 2012, (the default instance name for this is MSSQLSERVER) and the SQL Express should have an instance name of SQLEXPRESS (if I remember correctly) you'll need to use the naming convention server\instance to make the connection (you probably knew this bit already)
Try this
EXEC sp_updatestats;
MSDN
I'm installing a program that often throws an exception due to either a wrong parameter in an INSERT statement or permission problems on the database. I do have full administrative rights on the SQL Server and it would be nice to log failed INSERTs etc. and the reason why they failed. The stack trace from the C# code shows only that a parameter is too long, but not which one of them and what the value was. Therefore it would be the easiest solution to solve SQL problems via SQL Server Studio Management rather than making code changes to a release of a product.
The values of parameters can be viewed in SQL Server Profiler (Sql Server Management Studio: Tools -> SQL Server Profiler). It can be configured to save trace to db (if you can't reproduce an issue on test environment), and catch only certain calls (for example you can specify the name of your stored procedure).
Here is screen shot of profiler with stored procedures calls with all parameters: