Thursday, March 29, 2012
determine system database...
database through tsql?
The only tangible thing that I can see is dbid. however I would far rather a
database property to check in t-sql.
Thanks in advance,
M.Here is some idea.
Check how Microsoft guys are doing that. Build a simple application that
uses Microsoft.SqlServer.Management.Smo.Database.IsSystemObject property
for each database. Run Profiler and see how SMO is checking if the database
is a system database or not.
--
Regards
Pawel Potasinski
[http://www.potasinski.pl]
U¿ytkownik "Mark B" <nospam@.nospam.com> napisa³ w wiadomo¶ci
news:eEvpWO%23OIHA.4808@.TK2MSFTNGP05.phx.gbl...
> what is the best way to determine if a database is actually a system
> database through tsql?
> The only tangible thing that I can see is dbid. however I would far rather
> a database property to check in t-sql.
> Thanks in advance,
> M.
>|||cannot get it to work.
smo throws exception when I create the database object.
"Pawel Potasinski" <pawel.potasinski@.gmail.com> wrote in message
news:%23pkyNj%23OIHA.3816@.TK2MSFTNGP04.phx.gbl...
> Here is some idea.
> Check how Microsoft guys are doing that. Build a simple application that
> uses Microsoft.SqlServer.Management.Smo.Database.IsSystemObject property
> for each database. Run Profiler and see how SMO is checking if the
> database is a system database or not.
> --
> Regards
> Pawel Potasinski
> [http://www.potasinski.pl]
>
> U¿ytkownik "Mark B" <nospam@.nospam.com> napisa³ w wiadomo¶ci
> news:eEvpWO%23OIHA.4808@.TK2MSFTNGP05.phx.gbl...
>> what is the best way to determine if a database is actually a system
>> database through tsql?
>> The only tangible thing that I can see is dbid. however I would far
>> rather a database property to check in t-sql.
>> Thanks in advance,
>> M.
>|||To the best of my knowledge, there is no such property available anywhere. I believe that even SMO
and DMO goes by the database name.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
"Mark B" <nospam@.nospam.com> wrote in message news:eEvpWO%23OIHA.4808@.TK2MSFTNGP05.phx.gbl...
> what is the best way to determine if a database is actually a system database through tsql?
> The only tangible thing that I can see is dbid. however I would far rather a database property to
> check in t-sql.
> Thanks in advance,
> M.
>|||Exactly Tibor. More precisely - by they go by name for master, msdb, tempdb
and model but there's more. Distribution database for replication can have a
custom name and is also considered to be a system database so they also
check for the value of is_distributor column in sys.databases for each
database.
--
Regards
Pawel Potasinski
[http://www.potasinski.pl]
Uzytkownik "Tibor Karaszi"
<tibor_please.no.email_karaszi@.hotmail.nomail.com> napisal w wiadomosci
news:5900A85D-F0B1-4BAE-9FA4-BC2E37AB28CE@.microsoft.com...
> To the best of my knowledge, there is no such property available anywhere.
> I believe that even SMO and DMO goes by the database name.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://sqlblog.com/blogs/tibor_karaszi
>
> "Mark B" <nospam@.nospam.com> wrote in message
> news:eEvpWO%23OIHA.4808@.TK2MSFTNGP05.phx.gbl...
>> what is the best way to determine if a database is actually a system
>> database through tsql?
>> The only tangible thing that I can see is dbid. however I would far
>> rather a database property to check in t-sql.
>> Thanks in advance,
>> M.
>|||> so they also check for the value of is_distributor column in sys.databases for each database.
Ahh, that's good to know. Thanks Pawel.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
"Pawel Potasinski" <pawel.potasinski@.gmail.com> wrote in message
news:%23oXeDGQPIHA.4272@.TK2MSFTNGP06.phx.gbl...
> Exactly Tibor. More precisely - by they go by name for master, msdb, tempdb and model but there's
> more. Distribution database for replication can have a custom name and is also considered to be a
> system database so they also check for the value of is_distributor column in sys.databases for
> each database.
> --
> Regards
> Pawel Potasinski
> [http://www.potasinski.pl]
>
> Uzytkownik "Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> napisal w wiadomosci
> news:5900A85D-F0B1-4BAE-9FA4-BC2E37AB28CE@.microsoft.com...
>> To the best of my knowledge, there is no such property available anywhere. I believe that even
>> SMO and DMO goes by the database name.
>> --
>> Tibor Karaszi, SQL Server MVP
>> http://www.karaszi.com/sqlserver/default.asp
>> http://sqlblog.com/blogs/tibor_karaszi
>>
>> "Mark B" <nospam@.nospam.com> wrote in message news:eEvpWO%23OIHA.4808@.TK2MSFTNGP05.phx.gbl...
>> what is the best way to determine if a database is actually a system database through tsql?
>> The only tangible thing that I can see is dbid. however I would far rather a database property
>> to check in t-sql.
>> Thanks in advance,
>> M.
>>
>|||cannot get smo property to work!
"Pawel Potasinski" <pawel.potasinski@.gmail.com> wrote in message
news:%23pkyNj%23OIHA.3816@.TK2MSFTNGP04.phx.gbl...
> Here is some idea.
> Check how Microsoft guys are doing that. Build a simple application that
> uses Microsoft.SqlServer.Management.Smo.Database.IsSystemObject property
> for each database. Run Profiler and see how SMO is checking if the
> database is a system database or not.
> --
> Regards
> Pawel Potasinski
> [http://www.potasinski.pl]
>
> U¿ytkownik "Mark B" <nospam@.nospam.com> napisa³ w wiadomo¶ci
> news:eEvpWO%23OIHA.4808@.TK2MSFTNGP05.phx.gbl...
>> what is the best way to determine if a database is actually a system
>> database through tsql?
>> The only tangible thing that I can see is dbid. however I would far
>> rather a database property to check in t-sql.
>> Thanks in advance,
>> M.
>
Wednesday, March 21, 2012
Detect if a Job is running using TSQL
Is it possible to detect if a SQL Server Agent job is running using TSQL? I would like to programmatically determine if a job is running and take certain action if it is or isn't.
Thanks - Amos.
One simple way is to query the msdb.dbo.sysjobactivity table for the job and check to see if stop_execution_date is null. If it is, the job is running. At least that's my understanding.
sp_help_job returns a current_execution_status column. The problem with using this stored procedure is that it cannot be used in an insert...exec statement, because it has an insert...exec statement in it and these cannot be nested. You could go into the procedure and find the procedure it runs to get the job status, but that procedure is not documented.
Ron Rice
|||Using Books Online, look up sp_help_job.
For example,
EXECUTE sp_help_job
@.job_id = @.MyJobID [OR] @.job_name = @.MyJobName,@.execution_status > 0