显示标签为“delete”的博文。显示所有博文
显示标签为“delete”的博文。显示所有博文

2012年3月19日星期一

Disconnect All Ussers But Me

I have setup a small SSIS package that will regularly delete my log files by detaching the database, removing the file and then reattaching it.

Problem I'm having is that there is almost always at least one other connection to the database and I have to kill it for this to work.

Is there any TSQL command that allows me to shut down all open connections except the one the command is coming from?

There is no command like that. But you could use ALTER DATABASE to set the database in single user or restricted user mode. This may or may not work depending on the permissions of the login used by the SSIS package and how often the clients reconnect etc. Check out the ALTER DATABASE topic and see.

Btw, why are you recreating the log file periodically? What is the purpose?

|||

just to add what Umachander has already told.. read about Alter Database and Singler_User in BOL first

ALTER DATABASE SomeDatabase SET SiNGLE_USER WITH ROLLBACK IMMEDIATE;

and ofcourse answer the abovementioned questions also... very risky and unethical method of truncating and shrinking log.. not atall recommended and you should not do this. there are another /professional approach to control the growth and size of log file.

Refer this thread http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1272445&SiteID=1

Madhu

|||Thank you, I'll check those links out.

As for the reason, right now I inherited a database that is running some heavy SSIS packages, every time these run they do a lot of copying and deleting, in the end they inflate the log files drastically. However we don't really need the log files at all, we have all the data ready to be loaded in backup tapes should anything drastic happen.

I bet the SSIS packages can use a lot of optimization but for the time being I'm not in control of these and was instructed to take care of the logs ASAP. I already did this process manually and it worked so I figured it may be an OK temporary solution to run weekly until I got a hold of what is truly going on in this database and how to optimize it.

Heck, for the purposes of this project, if it was possible to disable logging as a permanent option, I'd do it.
|||If you aren't worried about he log files, then set the database recovery model to "simple". That will keep the logs much smaller and increase the speed of updates to the tables.

The way to shrink the log files is to use a maintenance plan. You can back it up and shrink the logs at night, which is what you are trying to do anyway.

Disconnect All Ussers But Me

I have setup a small SSIS package that will regularly delete my log files by detaching the database, removing the file and then reattaching it.

Problem I'm having is that there is almost always at least one other connection to the database and I have to kill it for this to work.

Is there any TSQL command that allows me to shut down all open connections except the one the command is coming from?

There is no command like that. But you could use ALTER DATABASE to set the database in single user or restricted user mode. This may or may not work depending on the permissions of the login used by the SSIS package and how often the clients reconnect etc. Check out the ALTER DATABASE topic and see.

Btw, why are you recreating the log file periodically? What is the purpose?

|||

just to add what Umachander has already told.. read about Alter Database and Singler_User in BOL first

ALTER DATABASE SomeDatabase SET SiNGLE_USER WITH ROLLBACK IMMEDIATE;

and ofcourse answer the abovementioned questions also... very risky and unethical method of truncating and shrinking log.. not atall recommended and you should not do this. there are another /professional approach to control the growth and size of log file.

Refer this thread http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1272445&SiteID=1

Madhu

|||Thank you, I'll check those links out.

As for the reason, right now I inherited a database that is running some heavy SSIS packages, every time these run they do a lot of copying and deleting, in the end they inflate the log files drastically. However we don't really need the log files at all, we have all the data ready to be loaded in backup tapes should anything drastic happen.

I bet the SSIS packages can use a lot of optimization but for the time being I'm not in control of these and was instructed to take care of the logs ASAP. I already did this process manually and it worked so I figured it may be an OK temporary solution to run weekly until I got a hold of what is truly going on in this database and how to optimize it.

Heck, for the purposes of this project, if it was possible to disable logging as a permanent option, I'd do it.|||If you aren't worried about he log files, then set the database recovery model to "simple". That will keep the logs much smaller and increase the speed of updates to the tables.

The way to shrink the log files is to use a maintenance plan. You can back it up and shrink the logs at night, which is what you are trying to do anyway.

2012年2月25日星期六

Disabling Foreign Key Constraint in Trigger

Hey,
Can anybody tell me how to disable a Foreign Key contraint from executing
while a Trigger is executing on DELETE event?
Best regards,
BillDRI are checked berofe the AFTER TRIGGERS, so if it is a problem the trigger
will not be fired.
AMB
"AST" wrote:

> Hey,
> Can anybody tell me how to disable a Foreign Key contraint from executing
> while a Trigger is executing on DELETE event?
> Best regards,
> Bill
>
>|||Hey AMB,
The table [HistoryDetails] has a FK on the column HistoryID that is being
used to enforce integrity with the table[History].
I am not sure if you are stating you can't disable the FK or if I have to
modify the context of the Trigger?
Best regards,
Bill
The Trigger is defined as:
/****** Object: Trigger dbo.TRIGGER_CascDeleteOnHistoryDetails Script
Date: 5/24/2002 12:14:53 AM ******/
CREATE TRIGGER [TRIGGER_CascDeleteOnHistoryDetails] ON dbo.History
FOR DELETE
AS
DELETE HistoryDetails FROM deleted, HistoryDetails WHERE deleted.HistoryID =
HistoryDetails.HistoryID
"Alejandro Mesa" <AlejandroMesa@.discussions.microsoft.com> wrote in message
news:4662B0B5-25C5-4217-84F0-B75E5ECCF604@.microsoft.com...
> DRI are checked berofe the AFTER TRIGGERS, so if it is a problem the
trigger
> will not be fired.
>
> AMB
>
> "AST" wrote:
>
executing|||That will make quite a mess:
1) Disabling a Foreign Key constraint is Data Definition Language, and can
only be executed by the table owner and members of the symin fixed server
roles and the db_owner and db_ddladmin database roles, and is not
transferable. So you have to give your users a large number of unnecessary
permissions.
2) Disabling a foreign key works for all connections, not just the current
one. So while you disable it in your trigger, someone else might need it.
What exactly are you trying to achieve? This is definitely not the right
way.
Jacco Schalkwijk
SQL Server MVP
"AST" <no_reply@.please.com> wrote in message
news:O50z0N6EFHA.3672@.TK2MSFTNGP14.phx.gbl...
> Hey,
> Can anybody tell me how to disable a Foreign Key contraint from executing
> while a Trigger is executing on DELETE event?
> Best regards,
> Bill
>|||Hey Jacco,
What I am trying to achieve is the following:
I have 2 tables [History], [HistoryDetails] where the Primary Table
[History] mantains detailed data in the [HistoryDetails] table. The key
relationship is History.HistoryID=> HistoryDetails.HistoryID.
I have place a constraint on the [HistoryDetails] table such that a record
cannot be added unless the HistoryID is existing in the [History] table.
I had also created a trigger to delete all relational records in the
[HistoryDetails] table when the Primary Key record in the [History] table
was deleted.
This is where I run into problems because the execution of the trigger fails
due to the FK Constraint.
Any suggestions would be very welcome?
Best regards,
Bill
"Jacco Schalkwijk" <jacco.please.reply@.to.newsgroups.mvps.org.invalid> wrote
in message news:uEUZEs6EFHA.2700@.TK2MSFTNGP14.phx.gbl...
> That will make quite a mess:
> 1) Disabling a Foreign Key constraint is Data Definition Language, and can
> only be executed by the table owner and members of the symin fixed
server
> roles and the db_owner and db_ddladmin database roles, and is not
> transferable. So you have to give your users a large number of unnecessary
> permissions.
> 2) Disabling a foreign key works for all connections, not just the current
> one. So while you disable it in your trigger, someone else might need it.
> What exactly are you trying to achieve? This is definitely not the right
> way.
> --
> Jacco Schalkwijk
> SQL Server MVP
>
> "AST" <no_reply@.please.com> wrote in message
> news:O50z0N6EFHA.3672@.TK2MSFTNGP14.phx.gbl...
executing
>|||Drop the trigger and use the ON DELETE CASCADE option on the foreign
key constraint.
David Portas
SQL Server MVP
--|||Hey David,
I don't think this is supported in SQL 7 and I have to support both SQL7 and
SQL2000
I tried running the SQL to add this constraint in SQL7 and it fails and
doesn't seem to recognize anthing to do with cascaded deletes?
Best regards,
Bill
"David Portas" <REMOVE_BEFORE_REPLYING_dportas@.acm.org> wrote in message
news:1108507933.414888.306670@.l41g2000cwc.googlegroups.com...
> Drop the trigger and use the ON DELETE CASCADE option on the foreign
> key constraint.
> --
> David Portas
> SQL Server MVP
> --
>|||AST
Well, you have to drop a FK constraint and to allow deletion within a
trigger.
"AST" <no_reply@.please.com> wrote in message
news:emTg1W8EFHA.624@.TK2MSFTNGP09.phx.gbl...
> Hey David,
> I don't think this is supported in SQL 7 and I have to support both SQL7
and
> SQL2000
> I tried running the SQL to add this constraint in SQL7 and it fails and
> doesn't seem to recognize anthing to do with cascaded deletes?
> Best regards,
> Bill
> "David Portas" <REMOVE_BEFORE_REPLYING_dportas@.acm.org> wrote in message
> news:1108507933.414888.306670@.l41g2000cwc.googlegroups.com...
>

2012年2月17日星期五

disable job

I'm using SQL server 2000
when i disable or delete a job, it returns
"Error 14274: Cannot add, update, or delete a job (or its steps or
schedules) that originated from an MSX server."Win
Examine MSDB..sysjobs system table. Probably there is ni match a server name
in originating_server column
"Win" <aaa@.aaa.com> wrote in message
news:%23Br9haUUGHA.5148@.TK2MSFTNGP12.phx.gbl...
> I'm using SQL server 2000
> when i disable or delete a job, it returns
> "Error 14274: Cannot add, update, or delete a job (or its steps or
> schedules) that originated from an MSX server."
>
>
>

2012年2月14日星期二

Disable all constraints in a table?

I have to delete records in quite a few of the tables of a DataWarehouse and
then populate them from else where. I'm not able to delete the records due to
Foreign Key constraints and I was wondering if there is a simpler way for me
to disable all the constraints in a table.
Thanks,
rgnI think you can use
alter table mytable nocheck constraint all
but I am not sure if it is a good idea as you will disable enforcing the
integrity of your data.
Hope this helps,
Ben Nevarez
Senior Database Administrator
AIG SunAmerica
"rgn" wrote:
> I have to delete records in quite a few of the tables of a DataWarehouse and
> then populate them from else where. I'm not able to delete the records due to
> Foreign Key constraints and I was wondering if there is a simpler way for me
> to disable all the constraints in a table.
> Thanks,
> rgn

Disable all constraints in a table?

I have to delete records in quite a few of the tables of a DataWarehouse and
then populate them from else where. I'm not able to delete the records due t
o
Foreign Key constraints and I was wondering if there is a simpler way for me
to disable all the constraints in a table.
Thanks,
rgnI think you can use
alter table mytable nocheck constraint all
but I am not sure if it is a good idea as you will disable enforcing the
integrity of your data.
Hope this helps,
Ben Nevarez
Senior Database Administrator
AIG SunAmerica
"rgn" wrote:

> I have to delete records in quite a few of the tables of a DataWarehouse a
nd
> then populate them from else where. I'm not able to delete the records due
to
> Foreign Key constraints and I was wondering if there is a simpler way for
me
> to disable all the constraints in a table.
> Thanks,
> rgn

Disable all constraints in a table?

I have to delete records in quite a few of the tables of a DataWarehouse and
then populate them from else where. I'm not able to delete the records due to
Foreign Key constraints and I was wondering if there is a simpler way for me
to disable all the constraints in a table.
Thanks,
rgn
I think you can use
alter table mytable nocheck constraint all
but I am not sure if it is a good idea as you will disable enforcing the
integrity of your data.
Hope this helps,
Ben Nevarez
Senior Database Administrator
AIG SunAmerica
"rgn" wrote:

> I have to delete records in quite a few of the tables of a DataWarehouse and
> then populate them from else where. I'm not able to delete the records due to
> Foreign Key constraints and I was wondering if there is a simpler way for me
> to disable all the constraints in a table.
> Thanks,
> rgn