I need to let a third party security app run a script as a
system admin to drop and recreate a database. Before this
will run, of course I need to make sure all connections to
that database are dropped.
Is there a command that will kill all connections to a
database?Sometimes you just have to trace other programs that can do this. I traced
what happens when you disconnect a database and someone is using it.
select spid from master..sysprocesses where dbid=db_id('<database name>')
Then that spid result is fed to a kill statement.
Should warn you that this is a tricky thing that you are doing. Certain
kinds of connections, such as those with SQL Query Analyzer and Enterprise
Manager, do not drop very easily. Sometimes connections keep going. A
drastic step might be to use a net stop/net start to restart MSSQLserver.
That will certainly free up all the connections, though the database might
go into recovery.
But no, if the Clear connection button on the Detach Database function in
SQL EM doesn't call a command, I doubt you are going to find one.
--
*******************************************************************
Andy S.
MCSE NT/2000, MCDBA SQL 7/2000
andymcdba1@.NOMORESPAM.yahoo.com
Please remove NOMORESPAM before replying.
Always keep your antivirus and Microsoft software
up to date with the latest definitions and product updates.
Be suspicious of every email attachment, I will never send
or post anything other than the text of a http:// link nor
post the link directly to a file for downloading.
This posting is provided "as is" with no warranties
and confers no rights.
*******************************************************************
"gotit" <anonymous@.discussions.microsoft.com> wrote in message
news:00a701c3d3b6$6be8e6c0$a401280a@.phx.gbl...
> I need to let a third party security app run a script as a
> system admin to drop and recreate a database. Before this
> will run, of course I need to make sure all connections to
> that database are dropped.
> Is there a command that will kill all connections to a
> database?|||Add these lines to the top of the script.
ALTER DATABASE 'MyDBName' SET OFFLINE WITH ROLLBACK IMMEDIATE
GO
ALTER DATABASE 'MyDBName' SET ONLINE
GO
--
Geoff N. Hiten
Microsoft SQL Server MVP
Senior Database Administrator
Careerbuilder.com
"gotit" <anonymous@.discussions.microsoft.com> wrote in message
news:00a701c3d3b6$6be8e6c0$a401280a@.phx.gbl...
> I need to let a third party security app run a script as a
> system admin to drop and recreate a database. Before this
> will run, of course I need to make sure all connections to
> that database are dropped.
> Is there a command that will kill all connections to a
> database?|||I know that I've seen a stored procedure on the net that will kill all
user connections. Try doing a search in google for something like "sp
kill all users" without the quotes.
Aaron
Andy Svendsen wrote:
> Sometimes you just have to trace other programs that can do this. I traced
> what happens when you disconnect a database and someone is using it.
> select spid from master..sysprocesses where dbid=db_id('<database name>')
> Then that spid result is fed to a kill statement.
> Should warn you that this is a tricky thing that you are doing. Certain
> kinds of connections, such as those with SQL Query Analyzer and Enterprise
> Manager, do not drop very easily. Sometimes connections keep going. A
> drastic step might be to use a net stop/net start to restart MSSQLserver.
> That will certainly free up all the connections, though the database might
> go into recovery.
> But no, if the Clear connection button on the Detach Database function in
> SQL EM doesn't call a command, I doubt you are going to find one.
>sql
Showing posts with label course. Show all posts
Showing posts with label course. Show all posts
Wednesday, March 21, 2012
Monday, March 19, 2012
Keys
hi
lets say i have table student(id,name) id =pk
table course(cno,cname)cn=pk
now iam a fresh graduate as i learned from uni if i want to get the couses that each student took i would make a table called studentcouse(id,cno) and put the two of them pk
now iam working and at work they told me to do so:studentcouse(studentcouse_serial,id,cno) studentcouse_serial=pk .but i told them that dublicate filed may occur amd they told me that we have a function that will remove dublicate.
so iam asking u if who is right me or them and if u can tell yr comments
thanx a lotWhy would you get duplicates in either? The link table either has a single col unique key (_serial) or a composite unique key (id+cno). In my eyes the _serial doesn't really serve any purpose. Perhaps they require only single col keys for some reason? But then again, what does the (_serial) actually contain?|||hi the serial is a pk for the table only
iam here just want to know what is the best way
composite keys or the serial that my co. use|||Well it's a long time since I checked up of CODDs db rule but I'm pretty sure the composite key is the purest approach. But that doesn't necessarily means it better. What is the reason they give for using the Serial column?|||they told me thats it better and as i know the db is science and i realy do not feel good to thier openion so i have asked
from my point of view is that if i have 1000000 records using thier option i must serach all recods to see if the new record i need to insert is found or not !!!!!!|||Not really, just because the primary key isn't the composite doesn't stop you having an composite index. Again though, why you bother having two indexes when you could just have one is still a bit odd.
lets say i have table student(id,name) id =pk
table course(cno,cname)cn=pk
now iam a fresh graduate as i learned from uni if i want to get the couses that each student took i would make a table called studentcouse(id,cno) and put the two of them pk
now iam working and at work they told me to do so:studentcouse(studentcouse_serial,id,cno) studentcouse_serial=pk .but i told them that dublicate filed may occur amd they told me that we have a function that will remove dublicate.
so iam asking u if who is right me or them and if u can tell yr comments
thanx a lotWhy would you get duplicates in either? The link table either has a single col unique key (_serial) or a composite unique key (id+cno). In my eyes the _serial doesn't really serve any purpose. Perhaps they require only single col keys for some reason? But then again, what does the (_serial) actually contain?|||hi the serial is a pk for the table only
iam here just want to know what is the best way
composite keys or the serial that my co. use|||Well it's a long time since I checked up of CODDs db rule but I'm pretty sure the composite key is the purest approach. But that doesn't necessarily means it better. What is the reason they give for using the Serial column?|||they told me thats it better and as i know the db is science and i realy do not feel good to thier openion so i have asked
from my point of view is that if i have 1000000 records using thier option i must serach all recods to see if the new record i need to insert is found or not !!!!!!|||Not really, just because the primary key isn't the composite doesn't stop you having an composite index. Again though, why you bother having two indexes when you could just have one is still a bit odd.
Subscribe to:
Posts (Atom)