Showing posts with label similar. Show all posts
Showing posts with label similar. Show all posts

Wednesday, March 28, 2012

Script to stop a SQL service

Is there a script that I can run to stop a particular SQL server service on
Win2003 server? I'm looking for a similar script to restart that service as
well. Thanks.NET START <service>
NET STOP <service
If you have a default instance install of SQL Server 200: "NET START
MSSQLSERVER"

Regards
----------
Mike Epprecht, Microsoft SQL Server MVP
Zurich, Switzerland

IM: mike@.epprecht.net

MVP Program: http://www.microsoft.com/mvp

Blog: http://www.msmvps.com/epprecht/

"Paul O. Morris" <pomorris@.comcast.net> wrote in message
news:K8GdnQw9easBP1vfRVn-gg@.comcast.com...
> Is there a script that I can run to stop a particular SQL server service
> on Win2003 server? I'm looking for a similar script to restart that
> service as well. Thanks.|||You can use the NET STOP and NET START commands from the command-prompt to
stop/start any Windows service. For a default SQL Server instance:

NET STOP MSSQLSERVER
NET START MSSQLSERVER

For a named instance:

NET STOP MSSQL$MyInstance
NET START MSSQL$MyInstance

You can also use SQL-DMO to stop/start a SQL Server instance. VbScript
Examples:

'stop example
Option Explicit
Dim oSQLServer
Set oSQLServer = CreateObject("SQLDMO.SQLServer")
oSQLServer.Name = "MyServer"
oSQLServer.Stop

'start example
Option Explicit
Dim oSQLServer
Set oSQLServer = CreateObject("SQLDMO.SQLServer")
oSQLServer.Start False, "MyServer"

--
Hope this helps.

Dan Guzman
SQL Server MVP

"Paul O. Morris" <pomorris@.comcast.net> wrote in message
news:K8GdnQw9easBP1vfRVn-gg@.comcast.com...
> Is there a script that I can run to stop a particular SQL server service
> on Win2003 server? I'm looking for a similar script to restart that
> service as well. Thanks.|||Would the syntax be the same if I ran the command line script from within a
batch file?

I'm planning on running this batch file from within the BackUp Exec
software. I have two database programs that run SQL services, preventing
the backup jobs from doing a thorough job. Automatically shutting down
those SQL services will allow jobs to complete properly.

"Dan Guzman" <guzmanda@.nospam-online.sbcglobal.net> wrote in message
news:Blyxe.3037$cb6.823@.newssvr30.news.prodigy.com ...
> You can use the NET STOP and NET START commands from the command-prompt to
> stop/start any Windows service. For a default SQL Server instance:
> NET STOP MSSQLSERVER
> NET START MSSQLSERVER
> For a named instance:
> NET STOP MSSQL$MyInstance
> NET START MSSQL$MyInstance
> You can also use SQL-DMO to stop/start a SQL Server instance. VbScript
> Examples:
> 'stop example
> Option Explicit
> Dim oSQLServer
> Set oSQLServer = CreateObject("SQLDMO.SQLServer")
> oSQLServer.Name = "MyServer"
> oSQLServer.Stop
> 'start example
> Option Explicit
> Dim oSQLServer
> Set oSQLServer = CreateObject("SQLDMO.SQLServer")
> oSQLServer.Start False, "MyServer"
> --
> Hope this helps.
> Dan Guzman
> SQL Server MVP
> "Paul O. Morris" <pomorris@.comcast.net> wrote in message
> news:K8GdnQw9easBP1vfRVn-gg@.comcast.com...
>> Is there a script that I can run to stop a particular SQL server service
>> on Win2003 server? I'm looking for a similar script to restart that
>> service as well. Thanks.
>>
>>|||> Would the syntax be the same if I ran the command line script from within
> a batch file?

Yes.

> I'm planning on running this batch file from within the BackUp Exec
> software. I have two database programs that run SQL services, preventing
> the backup jobs from doing a thorough job. Automatically shutting down
> those SQL services will allow jobs to complete properly.

Rather than cold backups, consider backing up your databases to disk using
Transact-SQL BACKUP DATABASE and then archiving the disk backup files to
tape using your backup software. This allows you to perform backups while
the databases are online and uses less tape storage. Many backup vendors
also provide a specialized backup agent for SQL Server that allows you to
backup SQL Server databases online.

In any case, be sure to thoroughly test your recovery procedure.

--
Hope this helps.

Dan Guzman
SQL Server MVP

"Paul O. Morris" <pomorris@.comcast.net> wrote in message
news:Y_-dncZAa9tM3lbfRVn-hQ@.comcast.com...
> Would the syntax be the same if I ran the command line script from within
> a batch file?
> I'm planning on running this batch file from within the BackUp Exec
> software. I have two database programs that run SQL services, preventing
> the backup jobs from doing a thorough job. Automatically shutting down
> those SQL services will allow jobs to complete properly.
>
> "Dan Guzman" <guzmanda@.nospam-online.sbcglobal.net> wrote in message
> news:Blyxe.3037$cb6.823@.newssvr30.news.prodigy.com ...
>> You can use the NET STOP and NET START commands from the command-prompt
>> to stop/start any Windows service. For a default SQL Server instance:
>>
>> NET STOP MSSQLSERVER
>> NET START MSSQLSERVER
>>
>> For a named instance:
>>
>> NET STOP MSSQL$MyInstance
>> NET START MSSQL$MyInstance
>>
>> You can also use SQL-DMO to stop/start a SQL Server instance. VbScript
>> Examples:
>>
>> 'stop example
>> Option Explicit
>> Dim oSQLServer
>> Set oSQLServer = CreateObject("SQLDMO.SQLServer")
>> oSQLServer.Name = "MyServer"
>> oSQLServer.Stop
>>
>> 'start example
>> Option Explicit
>> Dim oSQLServer
>> Set oSQLServer = CreateObject("SQLDMO.SQLServer")
>> oSQLServer.Start False, "MyServer"
>>
>> --
>> Hope this helps.
>>
>> Dan Guzman
>> SQL Server MVP
>>
>> "Paul O. Morris" <pomorris@.comcast.net> wrote in message
>> news:K8GdnQw9easBP1vfRVn-gg@.comcast.com...
>>> Is there a script that I can run to stop a particular SQL server service
>>> on Win2003 server? I'm looking for a similar script to restart that
>>> service as well. Thanks.
>>>
>>>
>>
>>|||Thanks, guys. I'll give it a shot.

"Dan Guzman" <guzmanda@.nospam-online.sbcglobal.net> wrote in message
news:zOQye.2686$vT3.2657@.newssvr30.news.prodigy.co m...
>> Would the syntax be the same if I ran the command line script from within
>> a batch file?
> Yes.
>> I'm planning on running this batch file from within the BackUp Exec
>> software. I have two database programs that run SQL services, preventing
>> the backup jobs from doing a thorough job. Automatically shutting down
>> those SQL services will allow jobs to complete properly.
> Rather than cold backups, consider backing up your databases to disk using
> Transact-SQL BACKUP DATABASE and then archiving the disk backup files to
> tape using your backup software. This allows you to perform backups while
> the databases are online and uses less tape storage. Many backup vendors
> also provide a specialized backup agent for SQL Server that allows you to
> backup SQL Server databases online.
> In any case, be sure to thoroughly test your recovery procedure.
> --
> Hope this helps.
> Dan Guzman
> SQL Server MVP
> "Paul O. Morris" <pomorris@.comcast.net> wrote in message
> news:Y_-dncZAa9tM3lbfRVn-hQ@.comcast.com...
>> Would the syntax be the same if I ran the command line script from within
>> a batch file?
>>
>> I'm planning on running this batch file from within the BackUp Exec
>> software. I have two database programs that run SQL services, preventing
>> the backup jobs from doing a thorough job. Automatically shutting down
>> those SQL services will allow jobs to complete properly.
>>
>>
>> "Dan Guzman" <guzmanda@.nospam-online.sbcglobal.net> wrote in message
>> news:Blyxe.3037$cb6.823@.newssvr30.news.prodigy.com ...
>>> You can use the NET STOP and NET START commands from the command-prompt
>>> to stop/start any Windows service. For a default SQL Server instance:
>>>
>>> NET STOP MSSQLSERVER
>>> NET START MSSQLSERVER
>>>
>>> For a named instance:
>>>
>>> NET STOP MSSQL$MyInstance
>>> NET START MSSQL$MyInstance
>>>
>>> You can also use SQL-DMO to stop/start a SQL Server instance. VbScript
>>> Examples:
>>>
>>> 'stop example
>>> Option Explicit
>>> Dim oSQLServer
>>> Set oSQLServer = CreateObject("SQLDMO.SQLServer")
>>> oSQLServer.Name = "MyServer"
>>> oSQLServer.Stop
>>>
>>> 'start example
>>> Option Explicit
>>> Dim oSQLServer
>>> Set oSQLServer = CreateObject("SQLDMO.SQLServer")
>>> oSQLServer.Start False, "MyServer"
>>>
>>> --
>>> Hope this helps.
>>>
>>> Dan Guzman
>>> SQL Server MVP
>>>
>>> "Paul O. Morris" <pomorris@.comcast.net> wrote in message
>>> news:K8GdnQw9easBP1vfRVn-gg@.comcast.com...
>>>> Is there a script that I can run to stop a particular SQL server
>>>> service on Win2003 server? I'm looking for a similar script to restart
>>>> that service as well. Thanks.
>>>>
>>>>
>>>
>>>
>>
>>

Wednesday, March 7, 2012

Script / Function ... to find difference b/w 2 similar tables

Hi,

I m searching for some Script / Function ... to find difference in data
b/w 2 similar tables (exactly same fields structure) in sql 2000.
plz update me asap !

thanks in advance !On 11 Jan 2005 22:34:27 -0800, AzGhanv/. wrote:

>I m searching for some Script / Function ... to find difference in data
>b/w 2 similar tables (exactly same fields structure) in sql 2000.
>plz update me asap !

Hi AzGhanv/.,

SELECT CASE
WHEN a.KeyCol = 1 THEN 'FirstTable'
ELSE 'SecondTable'
END AS Origin,
COALESCE (a.KeyCol1, b.KeyCol1) AS KeyCol1,
COALESCE (a.KeyCol2, b.KeyCol2) AS KeyCol2,
....
COALESCE (a.KeyColN, b.KeyColN) AS KeyColN,
COALESCE (a.DataCol1, b.DataCol1) AS DataCol1,
COALESCE (a.DataCol2, b.DataCol2) AS DataCol2,
....
COALESCE (a.DataColN, b.DataColN) AS DataColN
FROM FirstTable AS a
FULL OUTER JOIN SecondTable AS b
ON a.KeyCol1 = b.KeyCol1
AND a.KeyCol2 = b.KeyCol2
....
AND a.KeyColN = b.KeyColN
AND a.DataCol1 = b.DataCol1
AND a.DataCol2 = b.DataCol2
....
AND a.DataColN = b.DataColN

NOTE: The above assumes that no column may contain NULLS. For each data
column that allow NULLS, you'll have to replace

AND a.DataColX = b.DataColX

with

AND (a.DataColX = b.DataColX
OR (a.DataColX IS NULL AND b.DataColX IS NULL))

or, alternatively

AND NULLIF (a.DataColX, b.DataColX) IS NULL
AND NULLIF (b.DataColX, a.DataColX) IS NULL

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)|||Assuming by differences you mean rows in A not in B as well as vice
versa, a good solution would be

create table t1 (a int,b int)
create table t2 (a int,b int)

insert into t1 values (1,2)
insert into t1 values(3,4)
insert into t1 values(5,6)
insert into t2 values(1,2)
insert into t2 values(3,7)
insert into t2 values(5,6)

select sum(t) ,a,b from

(select 1 as t,* from t1
union all
select 2 as t,* from t2
) as both
group by a,b

this way you see both kinds of differences as 1 or 2, and 3 means no
difference (you can add having sum(t)<3 not to see them)
hope this helps
Tzvika