How to increase the timeout of a SQL Script job step? - sql

I have a SQL job running which contains 2 steps. One of them is of type (T-SQL Script) and I am facing timeout issue with it.
How can I configure the timeout for that specific job? (eventually for the job if the timeout is inherited). I use SQL Server 2008 R2
Thank you!

As per my understanding there is no option to set time-ot for T-Sql script in SQL jobs.Mainy this will happen when ther is hughe increase in the records of the underlying sql script.
check this article.
http://www.simple-talk.com/blogs/2012/07/16/sql-server-query-time-out-when-referencing-data-on-a-linked-server-2/

Related

SQL Workbench/J and BigQuery

I am currently using SQL Workbench/J as my GUI to interface and run queries for BigQuery, however I'm running into a 10 second timeout issue when running more complicated queries. Any advice on how to increase the default timeout limit? Is it accessible/changeable from within the GUI? The error message I'm receiving is this:
[Simba]BigQueryJDBCDriver The job has timed out on the server. Try increasing the timeout value. [SQL State=HY000, DB Errorcode=100034]
(PS: I set up SQL Workbench/J using these steps and this driver)
When you define the ConnectionString you are able to add driver properties. Timeout is one of the properties you can use.
Simply add:
jdbc:bigquery://...;Timeout=3600;

How to check if an SQL Script executed successfully in MS SQL Server?

I have created multiple SQL DB Maintenance scripts which I am required to run in a defined order. I have 2 scripts. I want to run the 2nd script, only on successful execution of 1st script. The scripts contain queries that creates tables, stored procedures, SQL jobs etc.
Please suggest an optimal way of achieving this. I am using MS SQL Server 2012.
I am trying to implement it without using an SQL job.
I'm sure I'm stating the obvious, and it's probably because I'm not fully understand what you meant by "executed successfully", but if you meant no SQL error while running:
The optimal way to achieve it is to create a job for your scripts, then create two steps - one for the first script and for the second. Once both steps are there, you go to the advanced options of step 1 and set it up to your needs.
Screenshot
Can you create a SQL Server Agent Job? You could just set the steps to be Step 1: Run first script, Step 2: run second script. In the agent job setup you can decide what to when step 1 fails. Just have it not run step 2. You can also set it up to email you, skip to another step, run some other code etc... If anything the first code did failed with any error message, your second script would not run. -- If you really needed to avoid a job, you could add some if exists statements to your second script, but that will get very messy very fast
If the two scripts are in different files
Add a statement which would log into a table the completion and date .Change second script to read this first and exit,if not success
if both are in same file
ensure they are in a transaction and read ##trancount at the start of second script and exit ,if less than 1
SQL Server 2005’s job scheduling subsystem, SQL Server Agent, maintains a set of log files with warning and error messages about the jobs it has run, written to the %ProgramFiles%\Microsoft SQL Server\MSSQL.1\MSSQL\LOG directory. SQL Server will maintain up to nine SQL Server Agent error log files. The current log file is named SQLAGENT .OUT, whereas archived files are numbered sequentially. You can view SQL Server Agent logs by using SQL Server Management Studio.

SQL Query - To stop/kill long running SQL job

I have a sql job who does some calculation in every 15 minutes.
Now i want to monitor this job. To check if that job is currently running and if yes then its been running for more than 10 minutes.
If it's running for more than 10 minutes then i want to stop/kill this job.
Is there any query available to do it?
Tried
EXEC msdb.dbo.sp_stop_job N'job name'
And it worked!
My best guess is you need SMO (SQL Server Management Objects) to pull this off. In particular take a look at the Job Class.

How to automatically update database SQL Server?

I need a field (column) of my database to update automatically. For example, the field NUMBER for each record incrementing every minute. How can I do it? I am using SQL Server.
You're probably looking for something called SQL Server Agent jobs
here is a good starting point reference:
http://technet.microsoft.com/en-us/library/ms181153(v=sql.105).aspx
This allows you to run some sql code on a schedule of your choosing.
P.S.
If you have access to sql server management studio, the GUI is much nicer.
You can set up a SQL Agent job to run an update statement once a minute:
UPDATE tablename
SET NUMBER = NUMBER + 1
Job Agent is only for full SQL Server. Then best choise. If you using SQL express then can't. You can solve with update
UPDATE TABLE-NAME SET
VALUE = VALUE + 1

Efficiently moving large sets of data between SQL Server tables?

I have a rather large (many gigabytes) table of data in SQL Server that I wish to move to a table in another database on the same server.
The tables are the same layout.
What would be the most effecient way of going about doing this?
This is a one off operation so no automation is required.
Many thanks.
If it is a one-off operation, why care about top efficiency so much?
SELECT * INTO OtherDatabase..NewTable FROM ThisDatabase..OldTable
or
INSERT OtherDatabase..NewTable
SELECT * FROM ThisDatabase..OldTable
...and let it run over night. I would dare to say that using SELECT/INSERT INTO on the same server is not far from the best efficiency you can get anyway.
Or you could use the "SQL Import and Export Wizard" found under "Management" in Microsoft SQL Server Management Studio.
I'd go with Tomalak's answer.
You might want to temporarily put your target database into bulk-logged recovery mode before executing a 'select into' to stop the log file exploding...
If it's SQL Server 7 or 2000 look at Data Transformation Services (DTS). For SQL 2005 and 2008 look at SQL Server Integration Services (SSIS)
Definitely put the target DB into bulk-logged mode. This will minimally log the operation and speed it up.