Showing posts with label easiest. Show all posts
Showing posts with label easiest. Show all posts

Wednesday, March 28, 2012

How do I launch an agent job from command line?

What is the easiest way to execute a SQL Agent (2005) job from the command line? I need to make a batch file to execute a reporting service shared schedule job.

Thanks in advance.

Refer to Books Online, Topic: 'DTExec utility'

DTExec.exe is the replacement for SQL 2000's DTSRun.exe.

|||Correct me if i'm wrong, but I think DTExec is just used for SSIS packages? I need to run the entire job. The job was generated by Reporting Services and I need to call it manually. Thanks a lot.|||

You're correct. I mis-interpreted your question.

You can use SQLCmd.exe, combined with a call to sp_startJob.

(If you are using SQL 2000, then use OSQL.exe instead of SQLCmd.)

Refer to Books Online for the complete syntax for either.

|||

Thanks a lot, I couldn't get the stored procedure to work but i just used the code that it mentioned in the Job properties window. The exact code for sqlcmd was: sqlcmd -Q "exec ReportServer.dbo.AddEvent @.EventType ='SharedSchedule', @.EventData='0dd48b88-6c35-4f3c-913e-b5299de948db'"

Thanks much.

Wednesday, March 21, 2012

How do i grab a simple list of SQL Server views, tables or sprocs?

I need just the names of tables, views and sprocs within a SQL Server
database. What's the easiest way to do this?[posted and mailed, please reply in news]

Kofi (kofisarfo@.gmail.com) writes:
> I need just the names of tables, views and sprocs within a SQL Server
> database. What's the easiest way to do this?

SELECT name FROM sysobjects WHERE xtype = 'U' -- Tables
SELECT name FROM sysobjects WHERE xtype = 'V' -- Views
SELECT name FROM sysobjects WHERE xtype = 'P' -- Stored Procedures

--
Erland Sommarskog, SQL Server MVP, sommar@.algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||"Kofi" <kofisarfo@.gmail.com> wrote in message
news:5c157557.0405111038.2cecb2cb@.posting.google.c om...
> I need just the names of tables, views and sprocs within a SQL Server
> database. What's the easiest way to do this?

SELECT table_name AS object_name,
table_schema AS schema_name,
table_type AS object_type
FROM INFORMATION_SCHEMA.TABLES
UNION ALL
SELECT routine_name AS object_name,
routine_schema AS schema_name,
routine_type AS object_type
FROM INFORMATION_SCHEMA.ROUTINES
WHERE routine_type = 'PROCEDURE'
ORDER BY object_type, schema_name, object_name

--
JAG|||Thanks Erland,

I was having a thick moment. I've used those SELECT statements
countless times before. Shame I was looking at the Master database
rather than the database I was in fact interested in.

But now I've a nice alternative below though :)

-- Kofi

Erland Sommarskog <sommar@.algonet.se> wrote in message news:<Xns94E71624A768Yazorman@.127.0.0.1>...
> [posted and mailed, please reply in news]
> Kofi (kofisarfo@.gmail.com) writes:
> > I need just the names of tables, views and sprocs within a SQL Server
> > database. What's the easiest way to do this?
> SELECT name FROM sysobjects WHERE xtype = 'U' -- Tables
> SELECT name FROM sysobjects WHERE xtype = 'V' -- Views
> SELECT name FROM sysobjects WHERE xtype = 'P' -- Stored Procedures