Showing posts with label delete. Show all posts
Showing posts with label delete. Show all posts

Tuesday, March 27, 2012

can we delete NT AUTHORITY\SYSTEM in sql server 2005?

Hi Folks,
In our sql server 2005 cluster server, we have a loginuser called
NT AUTHORITY\SYSTEM with sysadmin server role.
What is the purpose of that account?
Can we delete that login?
If we delete that will there be any problems?
We are using separate domain accounts for all sql services.
Please help.
Thank you
--KumarKumar,
Visit following link:
http://support.microsoft.com/kb/263712
NT AUTHORITY\SYSTEM restricts NT ADMIN and help to execute FullText as
FullText need builtin\administrators or NT AUTHORITY\SYSTEM.
Hope this will help.
"Kumar" wrote:
> Hi Folks,
> In our sql server 2005 cluster server, we have a loginuser called
> NT AUTHORITY\SYSTEM with sysadmin server role.
> What is the purpose of that account?
> Can we delete that login?
> If we delete that will there be any problems?
> We are using separate domain accounts for all sql services.
> Please help.
> Thank you
> --Kumarsql

Thursday, March 22, 2012

Can truncate but not delete

Hi
I have a 43,000 row table but can no longer delete the data from it all of a
sudden..it just hangs on the process and the processor shoots up to 100%. Bu
t
I have tried truncating this and it works, I know deleting logs every row
deleted but am not sure why I am getting this problem or what to monitor to
solve it.
Any help or advice would be great thanks
SammySammy
Do you have a WHERE clause in your DELETE statement?
Actually , DELETE and TRUNCATE commands are 'slightly' different in terms
how they do the job
DELETE command is fully logged (every row was deleted is recorded in TL) ,
as opposed TRUNCATE command which
logs only the deallocation of whole data pages
"Sammy" <Sammy@.discussions.microsoft.com> wrote in message
news:1B557178-E1BA-4D16-B4E8-2B9519856649@.microsoft.com...
> Hi
> I have a 43,000 row table but can no longer delete the data from it all of
> a
> sudden..it just hangs on the process and the processor shoots up to 100%.
> But
> I have tried truncating this and it works, I know deleting logs every row
> deleted but am not sure why I am getting this problem or what to monitor
> to
> solve it.
> Any help or advice would be great thanks
> Sammy|||Hi Uri,
No its just delete quotedetail it always worked before... but I get no
errors it just hangs so not sure what to check and how to solve this issue
"Uri Dimant" wrote:

> Sammy
> Do you have a WHERE clause in your DELETE statement?
>
> Actually , DELETE and TRUNCATE commands are 'slightly' different in terms
> how they do the job
> DELETE command is fully logged (every row was deleted is recorded in TL) ,
> as opposed TRUNCATE command which
> logs only the deallocation of whole data pages
> "Sammy" <Sammy@.discussions.microsoft.com> wrote in message
> news:1B557178-E1BA-4D16-B4E8-2B9519856649@.microsoft.com...
>
>|||So , do you have WHERE clause or you don't?
It is possible that blocks are occured because if you don't have an index on
the column in WHERE clause , SQL Server may lock entire table.
How many rows do you trying to delete?
"Sammy" <Sammy@.discussions.microsoft.com> wrote in message
news:6B563C5B-9D6E-44E5-AA43-404DA791730B@.microsoft.com...
> Hi Uri,
> No its just delete quotedetail it always worked before... but I get no
> errors it just hangs so not sure what to check and how to solve this issue
> "Uri Dimant" wrote:
>|||Here's a couple of things to check...
1. Is there another connection which has a lock on the table?
2. Is there a delete trigger on the table? This would be executing and the
problem could be there.
Regards
Colin Dawson
www.cjdawson.com
"Sammy" <Sammy@.discussions.microsoft.com> wrote in message
news:6B563C5B-9D6E-44E5-AA43-404DA791730B@.microsoft.com...
> Hi Uri,
> No its just delete quotedetail it always worked before... but I get no
> errors it just hangs so not sure what to check and how to solve this issue
> "Uri Dimant" wrote:
>|||Sammy (Sammy@.discussions.microsoft.com) writes:
> I have a 43,000 row table but can no longer delete the data from it all
> of a sudden..it just hangs on the process and the processor shoots up to
> 100%. But I have tried truncating this and it works, I know deleting
> logs every row deleted but am not sure why I am getting this problem or
> what to monitor to solve it.
> Any help or advice would be great thanks
Let's first rule out a few things it can't be:
o Blocking. Had it been a blocking issue, your processor would stay calm.
o Referencing foreign key. A delete operation can take a very long time
if there are referencing foreign keys that are not indexed, or if there
cascading deletes/updates. However, had there been referencing FKs,
SQL Server would not permit you to run TRUNCATE TABLE.
That leaves two options:
o There is a trigger on the table, and the trigger performs something
wild. TRUNCATE TABLE does not fire triggers, so it could not cause
this problem.
o The log file (or the data file) is full, and needs to autogrow. If the
the database is large, and you have the default 10% autogrow, this can
give quite an impact. As TRUNCATE TABLE just logs the extent
deallocations, it causes far less load.
Thus you should examine if you have triggers on the table, and run
and run DBCC SQLPERF ( LOGSPACE ) to determine how log space you have
in use.
--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||No triggers or other processes accessing the table, its a 44,000 row table
and delete quotedetail (no where clause in the delete command) does not work
but truncate table quotedetail works with no problems.
Have u any other ideas how to reslove this as I am stumped?
"Colin Dawson" wrote:

> Here's a couple of things to check...
>
> 1. Is there another connection which has a lock on the table?
> 2. Is there a delete trigger on the table? This would be executing and th
e
> problem could be there.
>
> --
> Regards
> Colin Dawson
> www.cjdawson.com
>
> "Sammy" <Sammy@.discussions.microsoft.com> wrote in message
> news:6B563C5B-9D6E-44E5-AA43-404DA791730B@.microsoft.com...
>
>|||Hi Erland I discovered it was part of a snapshot replication, I did not thin
k
it was part of replication as I could truncate the table but I guess its onl
y
merge and transactional replication that does not allow you to truncate the
tables. But I don't think this should affect my problem.
My processor queue length goes up to 25 when the delete command is run and
I think my processor might be having problems now and may need to be replace
d
to solve this issue.
"Erland Sommarskog" wrote:

> Sammy (Sammy@.discussions.microsoft.com) writes:
> Let's first rule out a few things it can't be:
> o Blocking. Had it been a blocking issue, your processor would stay calm.
> o Referencing foreign key. A delete operation can take a very long time
> if there are referencing foreign keys that are not indexed, or if there
> cascading deletes/updates. However, had there been referencing FKs,
> SQL Server would not permit you to run TRUNCATE TABLE.
> That leaves two options:
> o There is a trigger on the table, and the trigger performs something
> wild. TRUNCATE TABLE does not fire triggers, so it could not cause
> this problem.
> o The log file (or the data file) is full, and needs to autogrow. If the
> the database is large, and you have the default 10% autogrow, this can
> give quite an impact. As TRUNCATE TABLE just logs the extent
> deallocations, it causes far less load.
> Thus you should examine if you have triggers on the table, and run
> and run DBCC SQLPERF ( LOGSPACE ) to determine how log space you have
> in use.
> --
> Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
> Books Online for SQL Server 2005 at
> http://www.microsoft.com/technet/pr...oads/books.mspx
> Books Online for SQL Server 2000 at
> http://www.microsoft.com/sql/prodin...ions/books.mspx
>|||Sammy (Sammy@.discussions.microsoft.com) writes:
> Hi Erland I discovered it was part of a snapshot replication, I did not
> think it was part of replication as I could truncate the table but I
> guess its only merge and transactional replication that does not allow
> you to truncate the tables. But I don't think this should affect my
> problem. My processor queue length goes up to 25 when the delete command
> is run and I think my processor might be having problems now and may
> need to be replaced to solve this issue.
Ah, so replication set in? That was interesting to hear, as I'm not
doing much replication myself. Good to know, the next time someone
else asks a similar question.
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||See some details/background data on "Live-Lock" vs. "Dead-Lock" in SQL
Server:
http://www.dbforums.com/showthread...099#post4505099
It also gives some coverage on data accessibility in SQL Server.
You can download as a FREE-WARE SQL Server package that detects
Live-lock situations on SQL Server (and notifies production DBA, if
configured).
(SQL Server Live_Lock_Monitor).
It also continuously monitors/logs SQL Server Response time (and
notifies DBA if very slow response detected).
Note: SQL Server can "Freese" when it:
1) Automatically "Expands" any database (DB options set to "Autogrow"-
NOT recommended in production)
2) When programmer misses the join (cross product or Cartesian product)
3) when a number of processes are lined up to access some resource
(e.g. table, being heavily updated)
4) table scans against large tables done
5) a table is locked (reindexation, DBCC operation etc)
6) a lot of data is being "pumped" to the client side (i.e. programmer
writes:
SELECT * from Users (against tables with millions of rows)
and in a lot of other scenarios.
Most of them (not all) should be detected by the package (since actual
response time is measured).
Alexei Akimov

Wednesday, March 7, 2012

Can SQL Lose Records?

We are running SQL 7 with a front end that links to the tables through ODBC.
In our main table, the user has no way to delete a record through the
interface, though it is possible to delete it by opening the ODBC link.
Users would have no reason to delete a record, but one of our records turned
up missing.

Now, it's possible that a user may have accidentally deleted the record.
But, since users don't have any reason to delete records, and since they
don't access the ODBC links, it seems unlikely (though possible).

I was wondering if anyone had every heard of SQL Server ever "losing" a
record that had previously been saved. I checked the nightly backup from the
night after it was added, and the record was there. So either a user deleted
it, or somehow it got lost in SQL Server. I have no code that deletes
records in this table in any way, shape or form, so it couldn't have been
malfunctioning code.

So, while I have a hard time believing that SQL Server would just "lose" a
record, I also know that anything's possible, so I thought I'd ask if anyone
had ever heard of such a thing.

Thanks!

NeilOn Jun 20, 2:53 pm, "Neil" <nos...@.nospam.netwrote:

Quote:

Originally Posted by

We are running SQL 7 with a front end that links to the tables through ODBC.
In our main table, the user has no way to delete a record through the
interface, though it is possible to delete it by opening the ODBC link.
Users would have no reason to delete a record, but one of our records turned
up missing.
>
Now, it's possible that a user may have accidentally deleted the record.
But, since users don't have any reason to delete records, and since they
don't access the ODBC links, it seems unlikely (though possible).
>
I was wondering if anyone had every heard of SQL Server ever "losing" a
record that had previously been saved. I checked the nightly backup from the
night after it was added, and the record was there. So either a user deleted
it, or somehow it got lost in SQL Server. I have no code that deletes
records in this table in any way, shape or form, so it couldn't have been
malfunctioning code.
>
So, while I have a hard time believing that SQL Server would just "lose" a
record, I also know that anything's possible, so I thought I'd ask if anyone
had ever heard of such a thing.
>
Thanks!
>
Neil


Never heard of it. Revoke delete permissions from all your users. Add
a trigger prohibiting any deletes.|||I've never seen or heard of a row going missing either, and I spent
plenty of time using 7.0.

Along with what Alex suggested I would suggest doing a complete set of
DBCC integrity checks on the database.

Roy Harvey
Beacon Falls, CT

On Wed, 20 Jun 2007 19:53:32 GMT, "Neil" <nospam@.nospam.netwrote:

Quote:

Originally Posted by

>We are running SQL 7 with a front end that links to the tables through ODBC.
>In our main table, the user has no way to delete a record through the
>interface, though it is possible to delete it by opening the ODBC link.
>Users would have no reason to delete a record, but one of our records turned
>up missing.
>
>Now, it's possible that a user may have accidentally deleted the record.
>But, since users don't have any reason to delete records, and since they
>don't access the ODBC links, it seems unlikely (though possible).
>
>I was wondering if anyone had every heard of SQL Server ever "losing" a
>record that had previously been saved. I checked the nightly backup from the
>night after it was added, and the record was there. So either a user deleted
>it, or somehow it got lost in SQL Server. I have no code that deletes
>records in this table in any way, shape or form, so it couldn't have been
>malfunctioning code.
>
>So, while I have a hard time believing that SQL Server would just "lose" a
>record, I also know that anything's possible, so I thought I'd ask if anyone
>had ever heard of such a thing.
>
>Thanks!
>
>Neil

|||Neil (nospam@.nospam.net) writes:

Quote:

Originally Posted by

So, while I have a hard time believing that SQL Server would just "lose"
a record, I also know that anything's possible, so I thought I'd ask if
anyone had ever heard of such a thing.


Well, I have lost rows, but that was a on a system where no one was looking
at the event log or the DBCC logs, and finally the database broke down,
with several levels of corruption.

As Roy said, run DBCC. If it comes up with corruption, then that may be
the answer.

But I'm prepared to place my bets that there was a human involved.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||

Quote:

Originally Posted by

Never heard of it. Revoke delete permissions from all your users. Add
a trigger prohibiting any deletes.
>


If I add a trigger prohibiting any deletes, then it wouldn't be possible for
me to go in and delete a record if I ever needed to, right? Or is there a
way to set up a trigger so that it can allow the delete in some cases?

Thanks.|||I'm not familiar with DBCC. Can you point me in the right direction?

Thanks.

"Erland Sommarskog" <esquel@.sommarskog.sewrote in message
news:Xns9955ED0DF77BAYazorman@.127.0.0.1...

Quote:

Originally Posted by

Neil (nospam@.nospam.net) writes:

Quote:

Originally Posted by

>So, while I have a hard time believing that SQL Server would just "lose"
>a record, I also know that anything's possible, so I thought I'd ask if
>anyone had ever heard of such a thing.


>
Well, I have lost rows, but that was a on a system where no one was
looking
at the event log or the DBCC logs, and finally the database broke down,
with several levels of corruption.
>
As Roy said, run DBCC. If it comes up with corruption, then that may be
the answer.
>
But I'm prepared to place my bets that there was a human involved.
>
>
--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
>
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx

|||On Jun 20, 5:01 pm, "Neil" <nos...@.nospam.netwrote:

Quote:

Originally Posted by

Quote:

Originally Posted by

Never heard of it. Revoke delete permissions from all your users. Add
a trigger prohibiting any deletes.


>
If I add a trigger prohibiting any deletes, then it wouldn't be possible for
me to go in and delete a record if I ever needed to, right? Or is there a
way to set up a trigger so that it can allow the delete in some cases?
>
Thanks.


You can disable the trigger for the duration of your delete.
Alternatively you can have you trigger allow you to do whatever you
want, based on user_id() or suser_id(). Trigger can be bypassed using
nested triggers and or recursive trigger setting. There are other ways
best described in T-SQL Programming by Itzik Ben-Gan.

http://sqlserver-tips.blogspot.com/|||Neil (nospam@.nospam.net) writes:

Quote:

Originally Posted by

I'm not familiar with DBCC. Can you point me in the right direction?


There are several DBCC commands, but the one of interest here is DBCC
CHECKDB which checks the database for consistency errors. If the database is
of any size, run it off-hours.

You should regularly run DBCC on your database, for instance as part of a
maintenance job, and make sure that you get alerted if it finds any errors.

If memory serves, you just say "DBCC CHECKDB" in the database you want to
examine. But check Books Online for details.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||Hello,

You can think of SQL Profiler as well if still you doubt on the SQL
Activities for some particular time.

Thanks
Ajay

Friday, February 24, 2012

Can some explain this to me?

Hello,

I run the following query on a database (SQL 2005):

delete from person where pers_companyid in (select pers_companyid from
company where comp_expiry is not null)

I wanted to delete all people associated with a company which had an
expiry date. The mistake I made was that the column pers_companyid
does not exist. It should have been comp_companyid.

However, the query ran anyway and deleted all records from my person
table? If I run the subquery on its own then it doesn't run as the
column is missing.

Shouldn't I have got an error running this query?

Thanks,

DavidThe behavior is expected, if very painful in this case.

A subquery can reference any column in any table in the FROM clause of
the subquery, but it can also reference any column in any table from
the outer query. The reference to pers_companyid in the subquery was
resolved against the outer query table person. Had it been a column
in the subquery table company it would have acted as you intended.

The way to avoid this is to always qualify all column references in a
subquery. For a query such as this it would also make sense to
execute the subquery alone before executing the DELETE. It is also a
good idea to run a query first that establishes how many rows are to
be deleted and check that the number makes sense. Then run the DELETE
inside a transaction and if the count is different roll the
transaction back.

Roy Harvey
Beacon Falls, CT

On Thu, 25 Oct 2007 11:27:23 -0000, davidaustinarcher@.gmail.com wrote:

Quote:

Originally Posted by

>Hello,
>
>I run the following query on a database (SQL 2005):
>
>delete from person where pers_companyid in (select pers_companyid from
>company where comp_expiry is not null)
>
>I wanted to delete all people associated with a company which had an
>expiry date. The mistake I made was that the column pers_companyid
>does not exist. It should have been comp_companyid.
>
>However, the query ran anyway and deleted all records from my person
>table? If I run the subquery on its own then it doesn't run as the
>column is missing.
>
>Shouldn't I have got an error running this query?
>
>Thanks,
>
>David

|||>>. The mistake I made was that the column pers_companyid does not exist. It should have been comp_companyid. <<

Google for a recent posting of mine on scoping rules in SQL. Then
learn how to properly name data elements -- why is a personnel
company_id a totally different kind of attribute from a company
company_id? That is what different names imply! If you had obeyed
ISO-11179, your query would have run as intended.

DELETE FROM Personnel -- collective name
WHERE company_id -- scopes to Personnel
IN (SELECT company_id -- scopes to Companies
FROM Companies -- plural name
WHERE contract_expiry IS NOT NULL);

Do entire companies expire in your data model? or does some
relationship between them and your personnel expire?

Get a copy of SQL PROGRAMMING STYLE and it will help clear up your
thinking.

Sunday, February 19, 2012

Can seem to get delete and exist to work right

Hi all,

I am writing a test result database in SQL 2K5 and one of the features I want to implement is a stored procedure that deletes the oldrecords while preserving a set number of records, the following is what my SP looks like

Procedure [dbo].[CleanResults]

@.RecsToKeep bigInt,

@.Output Int output

as

Declare @.Date Datetime

Declare @.Count bigint

set @.Date = getdate()

Select @.Count = Count(UniqueID) from [Main]

Print 'THE COUNT IS'

print @.Count

if ( @.Count > @.RecsToKeep) begin

set @.Count= @.Count - @.RecsToKeep

Print 'THE Number to delete is'

print @.Count

select TOP(@.Count) UniqueID from Main order By [Main].[TestDateTime] desc

Delete from [Main] where exists (select TOP(@.Count) * from Main order By [Main].[TestDateTime] desc);

set @.Output = @.Count

end

else begin

set @.Output = -1

end

whats odd is that the select staement will evaluate correctly and return the oldest record @.Count record, however the delete stament removes all the records. An advice would be appriciated.

Thanks Christopher

PS Any advice for using TOP with variables in MSDE 2k (as opposed to 2k5) would be appreciated

The WHERE EXISTS is not what you are wanting. Try this instead

Code Snippet

Delete from [Main] where UniqueID IN (select TOP(@.Count) UniqueID from Main order By [Main].[TestDateTime] desc);

This will just grab the first set of uniqueIDs and delete those records, which will be the correct number of records.|||

Thanks it worked

|||

You can try:

;with cte

as

(

select *, row_number() over(order by TestDateTime DESC) as rn

from Main

)

delete cte

where rn <= @.Count;

AMB