Hello.
I can't get SQL to delete the old backup and transaction
files.
I was told that there is a bug with Windows 95, 98 or ME
but that is not my case. I have SQL 2000 running on
Windows 2000.
What can I do?
Thanx.
Hector,
There was a thread on this recently which can be viewed here:
Subject: Re: Maintenence Plan
http://tinyurl.com/5plnm
Does that help?
Mark Allison, SQL Server MVP
http://www.markallison.co.uk
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Hector wrote:
> Hello.
> I can't get SQL to delete the old backup and transaction
> files.
> I was told that there is a bug with Windows 95, 98 or ME
> but that is not my case. I have SQL 2000 running on
> Windows 2000.
> What can I do?
> Thanx.
>
|||I read it and it could be my situation.
Thanx Mark!
>--Original Message--
>Hector,
>There was a thread on this recently which can be viewed
here:[vbcol=seagreen]
>Subject: Re: Maintenence Plan
>http://tinyurl.com/5plnm
>Does that help?
>--
>Mark Allison, SQL Server MVP
>http://www.markallison.co.uk
>Looking for a SQL Server replication book?
>http://www.nwsu.com/0974973602.html
>
>Hector wrote:
transaction
>.
>
Showing posts with label delete. Show all posts
Showing posts with label delete. Show all posts
Monday, March 12, 2012
Expired Backup Files
Hello.
I can't get SQL to delete the old backup and transaction
files.
I was told that there is a bug with Windows 95, 98 or ME
but that is not my case. I have SQL 2000 running on
Windows 2000.
What can I do?
Thanx.Hector,
There was a thread on this recently which can be viewed here:
Subject: Re: Maintenence Plan
http://tinyurl.com/5plnm
Does that help?
--
Mark Allison, SQL Server MVP
http://www.markallison.co.uk
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Hector wrote:
> Hello.
> I can't get SQL to delete the old backup and transaction
> files.
> I was told that there is a bug with Windows 95, 98 or ME
> but that is not my case. I have SQL 2000 running on
> Windows 2000.
> What can I do?
> Thanx.
>|||I read it and it could be my situation.
Thanx Mark!
>--Original Message--
>Hector,
>There was a thread on this recently which can be viewed
here:
>Subject: Re: Maintenence Plan
>http://tinyurl.com/5plnm
>Does that help?
>--
>Mark Allison, SQL Server MVP
>http://www.markallison.co.uk
>Looking for a SQL Server replication book?
>http://www.nwsu.com/0974973602.html
>
>Hector wrote:
>> Hello.
>> I can't get SQL to delete the old backup and
transaction
>> files.
>> I was told that there is a bug with Windows 95, 98 or ME
>> but that is not my case. I have SQL 2000 running on
>> Windows 2000.
>> What can I do?
>> Thanx.
>.
>
I can't get SQL to delete the old backup and transaction
files.
I was told that there is a bug with Windows 95, 98 or ME
but that is not my case. I have SQL 2000 running on
Windows 2000.
What can I do?
Thanx.Hector,
There was a thread on this recently which can be viewed here:
Subject: Re: Maintenence Plan
http://tinyurl.com/5plnm
Does that help?
--
Mark Allison, SQL Server MVP
http://www.markallison.co.uk
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Hector wrote:
> Hello.
> I can't get SQL to delete the old backup and transaction
> files.
> I was told that there is a bug with Windows 95, 98 or ME
> but that is not my case. I have SQL 2000 running on
> Windows 2000.
> What can I do?
> Thanx.
>|||I read it and it could be my situation.
Thanx Mark!
>--Original Message--
>Hector,
>There was a thread on this recently which can be viewed
here:
>Subject: Re: Maintenence Plan
>http://tinyurl.com/5plnm
>Does that help?
>--
>Mark Allison, SQL Server MVP
>http://www.markallison.co.uk
>Looking for a SQL Server replication book?
>http://www.nwsu.com/0974973602.html
>
>Hector wrote:
>> Hello.
>> I can't get SQL to delete the old backup and
transaction
>> files.
>> I was told that there is a bug with Windows 95, 98 or ME
>> but that is not my case. I have SQL 2000 running on
>> Windows 2000.
>> What can I do?
>> Thanx.
>.
>
Expired Backup Files
Hello.
I can't get SQL to delete the old backup and transaction
files.
I was told that there is a bug with Windows 95, 98 or ME
but that is not my case. I have SQL 2000 running on
Windows 2000.
What can I do?
Thanx.Hector,
There was a thread on this recently which can be viewed here:
Subject: Re: Maintenence Plan
http://tinyurl.com/5plnm
Does that help?
Mark Allison, SQL Server MVP
http://www.markallison.co.uk
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Hector wrote:
> Hello.
> I can't get SQL to delete the old backup and transaction
> files.
> I was told that there is a bug with Windows 95, 98 or ME
> but that is not my case. I have SQL 2000 running on
> Windows 2000.
> What can I do?
> Thanx.
>|||I read it and it could be my situation.
Thanx Mark!
>--Original Message--
>Hector,
>There was a thread on this recently which can be viewed
here:
>Subject: Re: Maintenence Plan
>http://tinyurl.com/5plnm
>Does that help?
>--
>Mark Allison, SQL Server MVP
>http://www.markallison.co.uk
>Looking for a SQL Server replication book?
>http://www.nwsu.com/0974973602.html
>
>Hector wrote:
transaction[vbcol=seagreen]
>.
>
I can't get SQL to delete the old backup and transaction
files.
I was told that there is a bug with Windows 95, 98 or ME
but that is not my case. I have SQL 2000 running on
Windows 2000.
What can I do?
Thanx.Hector,
There was a thread on this recently which can be viewed here:
Subject: Re: Maintenence Plan
http://tinyurl.com/5plnm
Does that help?
Mark Allison, SQL Server MVP
http://www.markallison.co.uk
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Hector wrote:
> Hello.
> I can't get SQL to delete the old backup and transaction
> files.
> I was told that there is a bug with Windows 95, 98 or ME
> but that is not my case. I have SQL 2000 running on
> Windows 2000.
> What can I do?
> Thanx.
>|||I read it and it could be my situation.
Thanx Mark!
>--Original Message--
>Hector,
>There was a thread on this recently which can be viewed
here:
>Subject: Re: Maintenence Plan
>http://tinyurl.com/5plnm
>Does that help?
>--
>Mark Allison, SQL Server MVP
>http://www.markallison.co.uk
>Looking for a SQL Server replication book?
>http://www.nwsu.com/0974973602.html
>
>Hector wrote:
transaction[vbcol=seagreen]
>.
>
Wednesday, March 7, 2012
Expanding timeout setting for a SQL 2000 database
I have a database with a lot of old records i want to delete.
when i try to make the delete, i get the timeout message.
I don't care that the delete job will run several hours, but for that i need
to configure a large timeout time for a specific database?
Somebody can advice me how to do that?
Thanks in advance,
BarakBarak
Try keep you transactions small, also you will not lock others during the
transaction.
SET ROWCOUNT 1000
WHILE 1 = 1
BEGIN
--Your DELETE statement
IF @.@.ROWCOUNT = 0
BEGIN
BREAK
END
ELSE
BEGIN
CHECKPOINT
END
END
SET ROWCOUNT 0
"Barak Turovsky" <baraktur@.mail.ru> wrote in message
news:#gDxj1t$DHA.2216@.TK2MSFTNGP10.phx.gbl...
> I have a database with a lot of old records i want to delete.
> when i try to make the delete, i get the timeout message.
> I don't care that the delete job will run several hours, but for that i
need
> to configure a large timeout time for a specific database?
> Somebody can advice me how to do that?
> Thanks in advance,
> Barak
>|||Barak Turovsky (baraktur@.mail.ru) writes:
> I have a database with a lot of old records i want to delete. when i try
> to make the delete, i get the timeout message. I don't care that the
> delete job will run several hours, but for that i need to configure a
> large timeout time for a specific database?
The timeout is a client-side thing, so this is nothing you set in your
database.
From where are you running your command? Many client libraries has a default
timeout of 30 seconds. Enterprise Manager has as well. Query Analyzer on
the other hand has no timeout by default.
Erland Sommarskog, SQL Server MVP, sommar@.algonet.se
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp
when i try to make the delete, i get the timeout message.
I don't care that the delete job will run several hours, but for that i need
to configure a large timeout time for a specific database?
Somebody can advice me how to do that?
Thanks in advance,
BarakBarak
Try keep you transactions small, also you will not lock others during the
transaction.
SET ROWCOUNT 1000
WHILE 1 = 1
BEGIN
--Your DELETE statement
IF @.@.ROWCOUNT = 0
BEGIN
BREAK
END
ELSE
BEGIN
CHECKPOINT
END
END
SET ROWCOUNT 0
"Barak Turovsky" <baraktur@.mail.ru> wrote in message
news:#gDxj1t$DHA.2216@.TK2MSFTNGP10.phx.gbl...
> I have a database with a lot of old records i want to delete.
> when i try to make the delete, i get the timeout message.
> I don't care that the delete job will run several hours, but for that i
need
> to configure a large timeout time for a specific database?
> Somebody can advice me how to do that?
> Thanks in advance,
> Barak
>|||Barak Turovsky (baraktur@.mail.ru) writes:
> I have a database with a lot of old records i want to delete. when i try
> to make the delete, i get the timeout message. I don't care that the
> delete job will run several hours, but for that i need to configure a
> large timeout time for a specific database?
The timeout is a client-side thing, so this is nothing you set in your
database.
From where are you running your command? Many client libraries has a default
timeout of 30 seconds. Enterprise Manager has as well. Query Analyzer on
the other hand has no timeout by default.
Erland Sommarskog, SQL Server MVP, sommar@.algonet.se
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp
Expanding timeout setting for a SQL 2000 database
I have a database with a lot of old records i want to delete.
when i try to make the delete, i get the timeout message.
I don't care that the delete job will run several hours, but for that i need
to configure a large timeout time for a specific database?
Somebody can advice me how to do that?
Thanks in advance,
BarakBarak
Try keep you transactions small, also you will not lock others during the
transaction.
SET ROWCOUNT 1000
WHILE 1 = 1
BEGIN
--Your DELETE statement
IF @.@.ROWCOUNT = 0
BEGIN
BREAK
END
ELSE
BEGIN
CHECKPOINT
END
END
SET ROWCOUNT 0
"Barak Turovsky" <baraktur@.mail.ru> wrote in message
news:#gDxj1t$DHA.2216@.TK2MSFTNGP10.phx.gbl...
> I have a database with a lot of old records i want to delete.
> when i try to make the delete, i get the timeout message.
> I don't care that the delete job will run several hours, but for that i
need
> to configure a large timeout time for a specific database?
> Somebody can advice me how to do that?
> Thanks in advance,
> Barak
>|||Barak Turovsky (baraktur@.mail.ru) writes:
> I have a database with a lot of old records i want to delete. when i try
> to make the delete, i get the timeout message. I don't care that the
> delete job will run several hours, but for that i need to configure a
> large timeout time for a specific database?
The timeout is a client-side thing, so this is nothing you set in your
database.
From where are you running your command? Many client libraries has a default
timeout of 30 seconds. Enterprise Manager has as well. Query Analyzer on
the other hand has no timeout by default.
Erland Sommarskog, SQL Server MVP, sommar@.algonet.se
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinfo/productdoc/2000/books.asp
when i try to make the delete, i get the timeout message.
I don't care that the delete job will run several hours, but for that i need
to configure a large timeout time for a specific database?
Somebody can advice me how to do that?
Thanks in advance,
BarakBarak
Try keep you transactions small, also you will not lock others during the
transaction.
SET ROWCOUNT 1000
WHILE 1 = 1
BEGIN
--Your DELETE statement
IF @.@.ROWCOUNT = 0
BEGIN
BREAK
END
ELSE
BEGIN
CHECKPOINT
END
END
SET ROWCOUNT 0
"Barak Turovsky" <baraktur@.mail.ru> wrote in message
news:#gDxj1t$DHA.2216@.TK2MSFTNGP10.phx.gbl...
> I have a database with a lot of old records i want to delete.
> when i try to make the delete, i get the timeout message.
> I don't care that the delete job will run several hours, but for that i
need
> to configure a large timeout time for a specific database?
> Somebody can advice me how to do that?
> Thanks in advance,
> Barak
>|||Barak Turovsky (baraktur@.mail.ru) writes:
> I have a database with a lot of old records i want to delete. when i try
> to make the delete, i get the timeout message. I don't care that the
> delete job will run several hours, but for that i need to configure a
> large timeout time for a specific database?
The timeout is a client-side thing, so this is nothing you set in your
database.
From where are you running your command? Many client libraries has a default
timeout of 30 seconds. Enterprise Manager has as well. Query Analyzer on
the other hand has no timeout by default.
Erland Sommarskog, SQL Server MVP, sommar@.algonet.se
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinfo/productdoc/2000/books.asp
Sunday, February 26, 2012
EXISTS problem with Delete
I have three tables (SHADES, CHANGES, AND SHADES_SUC)
Shades primary structure: Shade_ID
Changes primary structure: Old_Shade_ID
Shades_SUC primary structure Shade_ID
A record is written to Changes when a change is made to the Shades table and
some of these changes will cause a scenario where the Shades_SUC table will
hold orphaned children to the shade_ID
My delete statement is as follows:
DELETE
FROM SHADE
WHERE EXISTS
(
SELECT *
FROM CHANGES, SHADE
WHERE CHANGES.OLD_SHADE_ID = SHADE.SHADE_ID
AND CHANGES.OLD_SHADE_ID NOT IN
(SELECT SHADE_ID FROM SHADE_SUC)
)
If I highlight simply the select portion of Select * from Changes, shade...
I receive a return of 8 records - which is correct. However when I run the
entire Delete command the procedure deletes every record in the Shade table
-
I have tried numerous things - can anyone provide any direction on what I ma
y
be doing wrong here?
ThxSorry - I typed incorrectly - To Confirm... We are looking for any shades
that do not have any children in the Shades_SUC table - so that we can delet
e
them.
"Dan" wrote:
> I have three tables (SHADES, CHANGES, AND SHADES_SUC)
> Shades primary structure: Shade_ID
> Changes primary structure: Old_Shade_ID
> Shades_SUC primary structure Shade_ID
> A record is written to Changes when a change is made to the Shades table a
nd
> some of these changes will cause a scenario where the Shades_SUC table wil
l
> hold orphaned children to the shade_ID
> My delete statement is as follows:
> DELETE
> FROM SHADE
> WHERE EXISTS
> (
> SELECT *
> FROM CHANGES, SHADE
> WHERE CHANGES.OLD_SHADE_ID = SHADE.SHADE_ID
> AND CHANGES.OLD_SHADE_ID NOT IN
> (SELECT SHADE_ID FROM SHADE_SUC)
> )
> If I highlight simply the select portion of Select * from Changes, shade..
.
> I receive a return of 8 records - which is correct. However when I run th
e
> entire Delete command the procedure deletes every record in the Shade tabl
e -
> I have tried numerous things - can anyone provide any direction on what I
may
> be doing wrong here?
> Thx|||Thats correct you have to link the outer and the inner query to do this:
DELETE
FROM SHADE S
WHERE EXISTS
(
SELECT *
FROM CHANGES C
WHERE C.OLD_SHADE_ID = S.SHADE_ID
AND C.OLD_SHADE_ID NOT IN
(SELECT SHADE_ID FROM SHADE_SUC)
)
HTH, Jens Suessmeyer.
http://www.sqlserver2005.de
--
"Dan" <Dan@.discussions.microsoft.com> schrieb im Newsbeitrag
news:A9B07B01-E573-49D9-95C0-637F01724BCC@.microsoft.com...
>I have three tables (SHADES, CHANGES, AND SHADES_SUC)
> Shades primary structure: Shade_ID
> Changes primary structure: Old_Shade_ID
> Shades_SUC primary structure Shade_ID
> A record is written to Changes when a change is made to the Shades table
> and
> some of these changes will cause a scenario where the Shades_SUC table
> will
> hold orphaned children to the shade_ID
> My delete statement is as follows:
> DELETE
> FROM SHADE
> WHERE EXISTS
> (
> SELECT *
> FROM CHANGES, SHADE
> WHERE CHANGES.OLD_SHADE_ID = SHADE.SHADE_ID
> AND CHANGES.OLD_SHADE_ID NOT IN
> (SELECT SHADE_ID FROM SHADE_SUC)
> )
> If I highlight simply the select portion of Select * from Changes,
> shade...
> I receive a return of 8 records - which is correct. However when I run
> the
> entire Delete command the procedure deletes every record in the Shade
> table -
> I have tried numerous things - can anyone provide any direction on what I
> may
> be doing wrong here?
> Thx|||Try,
DELETE SHADE
WHERE EXISTS
(
SELECT
*
FROM
CHANGES
left join
SHADE_SUC
on CHANGES.OLD_SHADE_ID = SHADE_SUC.SHADE_ID
WHERE
CHANGES.OLD_SHADE_ID = SHADE.SHADE_ID
and SHADE_SUC.SHADE_ID is null
);
AMB
"Dan" wrote:
> I have three tables (SHADES, CHANGES, AND SHADES_SUC)
> Shades primary structure: Shade_ID
> Changes primary structure: Old_Shade_ID
> Shades_SUC primary structure Shade_ID
> A record is written to Changes when a change is made to the Shades table a
nd
> some of these changes will cause a scenario where the Shades_SUC table wil
l
> hold orphaned children to the shade_ID
> My delete statement is as follows:
> DELETE
> FROM SHADE
> WHERE EXISTS
> (
> SELECT *
> FROM CHANGES, SHADE
> WHERE CHANGES.OLD_SHADE_ID = SHADE.SHADE_ID
> AND CHANGES.OLD_SHADE_ID NOT IN
> (SELECT SHADE_ID FROM SHADE_SUC)
> )
> If I highlight simply the select portion of Select * from Changes, shade..
.
> I receive a return of 8 records - which is correct. However when I run th
e
> entire Delete command the procedure deletes every record in the Shade tabl
e -
> I have tried numerous things - can anyone provide any direction on what I
may
> be doing wrong here?
> Thx|||Please post DDL, so that people do not have to guess what the keys,
constraints, Declarative Referential Integrity, datatypes, etc. in your
schema are. Sample data is also a good idea, along with clear
specifications.
This soudns like you need to re-design the schema with a proper history
table and ON DELETE CASCADE actions.|||Receive the following:
Server: Msg 170, Level 15, State 1, Line 2
Line 2: Incorrect syntax near 'S'. -
Reveiwed but did not see anything obvious
"Jens Sü?meyer" wrote:
> Thats correct you have to link the outer and the inner query to do this:
>
> DELETE
> FROM SHADE S
> WHERE EXISTS
> (
> SELECT *
> FROM CHANGES C
> WHERE C.OLD_SHADE_ID = S.SHADE_ID
> AND C.OLD_SHADE_ID NOT IN
> (SELECT SHADE_ID FROM SHADE_SUC)
> )
> HTH, Jens Suessmeyer.
> --
> http://www.sqlserver2005.de
> --
>
> "Dan" <Dan@.discussions.microsoft.com> schrieb im Newsbeitrag
> news:A9B07B01-E573-49D9-95C0-637F01724BCC@.microsoft.com...
>
>|||No table alias in DELETE. Use the full name for S instead.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Dan" <Dan@.discussions.microsoft.com> wrote in message
news:63E6DC40-4883-4479-BAD8-78DC5DAA550B@.microsoft.com...
> Receive the following:
> Server: Msg 170, Level 15, State 1, Line 2
> Line 2: Incorrect syntax near 'S'. -
> Reveiwed but did not see anything obvious
> "Jens Smeyer" wrote:
>
Shades primary structure: Shade_ID
Changes primary structure: Old_Shade_ID
Shades_SUC primary structure Shade_ID
A record is written to Changes when a change is made to the Shades table and
some of these changes will cause a scenario where the Shades_SUC table will
hold orphaned children to the shade_ID
My delete statement is as follows:
DELETE
FROM SHADE
WHERE EXISTS
(
SELECT *
FROM CHANGES, SHADE
WHERE CHANGES.OLD_SHADE_ID = SHADE.SHADE_ID
AND CHANGES.OLD_SHADE_ID NOT IN
(SELECT SHADE_ID FROM SHADE_SUC)
)
If I highlight simply the select portion of Select * from Changes, shade...
I receive a return of 8 records - which is correct. However when I run the
entire Delete command the procedure deletes every record in the Shade table
-
I have tried numerous things - can anyone provide any direction on what I ma
y
be doing wrong here?
ThxSorry - I typed incorrectly - To Confirm... We are looking for any shades
that do not have any children in the Shades_SUC table - so that we can delet
e
them.
"Dan" wrote:
> I have three tables (SHADES, CHANGES, AND SHADES_SUC)
> Shades primary structure: Shade_ID
> Changes primary structure: Old_Shade_ID
> Shades_SUC primary structure Shade_ID
> A record is written to Changes when a change is made to the Shades table a
nd
> some of these changes will cause a scenario where the Shades_SUC table wil
l
> hold orphaned children to the shade_ID
> My delete statement is as follows:
> DELETE
> FROM SHADE
> WHERE EXISTS
> (
> SELECT *
> FROM CHANGES, SHADE
> WHERE CHANGES.OLD_SHADE_ID = SHADE.SHADE_ID
> AND CHANGES.OLD_SHADE_ID NOT IN
> (SELECT SHADE_ID FROM SHADE_SUC)
> )
> If I highlight simply the select portion of Select * from Changes, shade..
.
> I receive a return of 8 records - which is correct. However when I run th
e
> entire Delete command the procedure deletes every record in the Shade tabl
e -
> I have tried numerous things - can anyone provide any direction on what I
may
> be doing wrong here?
> Thx|||Thats correct you have to link the outer and the inner query to do this:
DELETE
FROM SHADE S
WHERE EXISTS
(
SELECT *
FROM CHANGES C
WHERE C.OLD_SHADE_ID = S.SHADE_ID
AND C.OLD_SHADE_ID NOT IN
(SELECT SHADE_ID FROM SHADE_SUC)
)
HTH, Jens Suessmeyer.
http://www.sqlserver2005.de
--
"Dan" <Dan@.discussions.microsoft.com> schrieb im Newsbeitrag
news:A9B07B01-E573-49D9-95C0-637F01724BCC@.microsoft.com...
>I have three tables (SHADES, CHANGES, AND SHADES_SUC)
> Shades primary structure: Shade_ID
> Changes primary structure: Old_Shade_ID
> Shades_SUC primary structure Shade_ID
> A record is written to Changes when a change is made to the Shades table
> and
> some of these changes will cause a scenario where the Shades_SUC table
> will
> hold orphaned children to the shade_ID
> My delete statement is as follows:
> DELETE
> FROM SHADE
> WHERE EXISTS
> (
> SELECT *
> FROM CHANGES, SHADE
> WHERE CHANGES.OLD_SHADE_ID = SHADE.SHADE_ID
> AND CHANGES.OLD_SHADE_ID NOT IN
> (SELECT SHADE_ID FROM SHADE_SUC)
> )
> If I highlight simply the select portion of Select * from Changes,
> shade...
> I receive a return of 8 records - which is correct. However when I run
> the
> entire Delete command the procedure deletes every record in the Shade
> table -
> I have tried numerous things - can anyone provide any direction on what I
> may
> be doing wrong here?
> Thx|||Try,
DELETE SHADE
WHERE EXISTS
(
SELECT
*
FROM
CHANGES
left join
SHADE_SUC
on CHANGES.OLD_SHADE_ID = SHADE_SUC.SHADE_ID
WHERE
CHANGES.OLD_SHADE_ID = SHADE.SHADE_ID
and SHADE_SUC.SHADE_ID is null
);
AMB
"Dan" wrote:
> I have three tables (SHADES, CHANGES, AND SHADES_SUC)
> Shades primary structure: Shade_ID
> Changes primary structure: Old_Shade_ID
> Shades_SUC primary structure Shade_ID
> A record is written to Changes when a change is made to the Shades table a
nd
> some of these changes will cause a scenario where the Shades_SUC table wil
l
> hold orphaned children to the shade_ID
> My delete statement is as follows:
> DELETE
> FROM SHADE
> WHERE EXISTS
> (
> SELECT *
> FROM CHANGES, SHADE
> WHERE CHANGES.OLD_SHADE_ID = SHADE.SHADE_ID
> AND CHANGES.OLD_SHADE_ID NOT IN
> (SELECT SHADE_ID FROM SHADE_SUC)
> )
> If I highlight simply the select portion of Select * from Changes, shade..
.
> I receive a return of 8 records - which is correct. However when I run th
e
> entire Delete command the procedure deletes every record in the Shade tabl
e -
> I have tried numerous things - can anyone provide any direction on what I
may
> be doing wrong here?
> Thx|||Please post DDL, so that people do not have to guess what the keys,
constraints, Declarative Referential Integrity, datatypes, etc. in your
schema are. Sample data is also a good idea, along with clear
specifications.
This soudns like you need to re-design the schema with a proper history
table and ON DELETE CASCADE actions.|||Receive the following:
Server: Msg 170, Level 15, State 1, Line 2
Line 2: Incorrect syntax near 'S'. -
Reveiwed but did not see anything obvious
"Jens Sü?meyer" wrote:
> Thats correct you have to link the outer and the inner query to do this:
>
> DELETE
> FROM SHADE S
> WHERE EXISTS
> (
> SELECT *
> FROM CHANGES C
> WHERE C.OLD_SHADE_ID = S.SHADE_ID
> AND C.OLD_SHADE_ID NOT IN
> (SELECT SHADE_ID FROM SHADE_SUC)
> )
> HTH, Jens Suessmeyer.
> --
> http://www.sqlserver2005.de
> --
>
> "Dan" <Dan@.discussions.microsoft.com> schrieb im Newsbeitrag
> news:A9B07B01-E573-49D9-95C0-637F01724BCC@.microsoft.com...
>
>|||No table alias in DELETE. Use the full name for S instead.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Dan" <Dan@.discussions.microsoft.com> wrote in message
news:63E6DC40-4883-4479-BAD8-78DC5DAA550B@.microsoft.com...
> Receive the following:
> Server: Msg 170, Level 15, State 1, Line 2
> Line 2: Incorrect syntax near 'S'. -
> Reveiwed but did not see anything obvious
> "Jens Smeyer" wrote:
>
Labels:
database,
delete,
exists,
microsoft,
mysql,
old_shade_idshades_suc,
oracle,
primary,
server,
shade_idchanges,
shades,
shades_suc,
sql,
structure,
tables
EXISTS or other construct to achieve FK table record deletion
I need one other favor. I am trying to delete the detail records from the
detail table before deleting the header record from the pk table. I have pu
t
together the following SQL. The SELECT statement gets the 2 records I need
from the detail table, but I'm not sure how to pass the ID's to the DELETE
part of the statement to get id of the details records. I have the overall
statement as a SELECT for now, until I work it all out. I will then change
the SELECT to a DELETE. I have included both versions for your review. I
would certainly appreciate your assistance. I can give you my phone number
if you'd like to speak in person more about my effort.
Gratefully,
Mark
CODE SAMPLE:
--
SELECT *
FROM jrnDTLGrantManagement AS Tdtl
WHERE EXISTS
-->this part gets the 2 records I'm looking for but the above returns 8000 +
record
-->ignoring the criteri below. Am I using the EXISTS incorrectly
-->TSum.IDJ is the PK below
-->Tdtl.IDJ is the FK
(SELECT * FROM jrnGrantManagement AS Tsum
INNER JOIN jrnDTLGrantManagement AS TDtl2 ON TSum.Idj = TDtl2.Idj
INNER JOIN mbrInitiative AS TInit ON Tdtl2.Initiative = TInit.ID
WHERE TInit.ParentH1 = 'CanadianBorder'
AND CONVERT(CHAR(8),TSum.DateModified,10) = '01-11-06')
when the above works, I plan to convert it to a DELETE statement as follows:
DELETE jrnDTLGrantManagement
FROM jrnDTLGrantManagement AS Tdtl
WHERE EXISTS
(SELECT * FROM jrnGrantManagement AS Tsum
INNER JOIN jrnDTLGrantManagement AS TDtl2 ON TSum.Idj = TDtl2.Idj
INNER JOIN mbrInitiative AS TInit ON Tdtl2.Initiative = TInit.ID
WHERE TInit.ParentH1 = 'CanadianBorder'
AND CONVERT(CHAR(8),TSum.DateModified,10) = '01-11-06')You should be able to accomplish this by creating a relationship with
"Cascade Delete Related Fields" selected.
This should let the database handle the deletes in the detail table
automatically when a record from the PK table is deleted. This requires no
coding, just point and click.
That said, if you really want to do it this way, here are a couple of
suggestions...
First, replace the * in your exists select with a litteral 1. I'm not
certain how SQL Server handles this, btu when I worked with Oracle selecting
1 rather than fields was less overhead, as no data had to actually be placed
in memory save the one. If anyone knows if this really makes a difference
or not, I would love to knwo for sure.
It looks like the problem with your exists is that you are not joining it to
your table in your select statement, so it is finding one row exists
regardless of which row you are looking at in the main select. Try adding a
criteria to your exists where it joins to the outer select (delete).
where TDtl2.Idj = TDtl.Idj
You could also make your exists an in clause, and select TDtl2.Idj in place
of *. Then just chang "where exists" to "where TDtl.Idj in" I'm not sure
how this will affect performance as I dont know your table structures.
Hope this helps.
"Mark in Miami" <MarkinMiami@.discussions.microsoft.com> wrote in message
news:BE80A9BA-401A-4E73-B4AC-4093F72A6D8B@.microsoft.com...
> I need one other favor. I am trying to delete the detail records from the
> detail table before deleting the header record from the pk table. I have
put
> together the following SQL. The SELECT statement gets the 2 records I
need
> from the detail table, but I'm not sure how to pass the ID's to the DELETE
> part of the statement to get id of the details records. I have the
overall
> statement as a SELECT for now, until I work it all out. I will then
change
> the SELECT to a DELETE. I have included both versions for your review. I
> would certainly appreciate your assistance. I can give you my phone
number
> if you'd like to speak in person more about my effort.
> Gratefully,
> Mark
> CODE SAMPLE:
> --
> SELECT *
> FROM jrnDTLGrantManagement AS Tdtl
> WHERE EXISTS
> -->this part gets the 2 records I'm looking for but the above returns 8000
+
> record
> -->ignoring the criteri below. Am I using the EXISTS incorrectly
> -->TSum.IDJ is the PK below
> -->Tdtl.IDJ is the FK
> (SELECT * FROM jrnGrantManagement AS Tsum
> INNER JOIN jrnDTLGrantManagement AS TDtl2 ON TSum.Idj = TDtl2.Idj
> INNER JOIN mbrInitiative AS TInit ON Tdtl2.Initiative = TInit.ID
> WHERE TInit.ParentH1 = 'CanadianBorder'
> AND CONVERT(CHAR(8),TSum.DateModified,10) = '01-11-06')
> when the above works, I plan to convert it to a DELETE statement as
follows:
> DELETE jrnDTLGrantManagement
> FROM jrnDTLGrantManagement AS Tdtl
> WHERE EXISTS
> (SELECT * FROM jrnGrantManagement AS Tsum
> INNER JOIN jrnDTLGrantManagement AS TDtl2 ON TSum.Idj = TDtl2.Idj
> INNER JOIN mbrInitiative AS TInit ON Tdtl2.Initiative = TInit.ID
> WHERE TInit.ParentH1 = 'CanadianBorder'
> AND CONVERT(CHAR(8),TSum.DateModified,10) = '01-11-06')
>|||DELETE jrnDTLGrantManagement
FROM jrnDTLGrantManagement AS Tdtl
WHERE EXISTS
(SELECT * FROM jrnGrantManagement AS Tsum
INNER JOIN mbrInitiative AS TInit ON Tdtl2.Initiative = TInit.ID
WHERE TInit.ParentH1 = 'CanadianBorder'
AND CONVERT(CHAR(8),TSum.DateModified,10) = '01-11-06'
)
This makes it a correlated subquery, and should work. First of course,
check my work by executing:
SELECT Tdtl.*
FROM jrnDTLGrantManagement AS Tdtl
WHERE EXISTS
(SELECT * FROM jrnGrantManagement AS Tsum
INNER JOIN jrnDTLGrantManagement AS TDtl2 ON TSum.Idj = TDtl2.Idj
INNER JOIN mbrInitiative AS TInit ON Tdtl2.Initiative = TInit.ID
WHERE TInit.ParentH1 = 'CanadianBorder'
AND CONVERT(CHAR(8),TSum.DateModified,10) = '01-11-06'
AND TSum.Idj = TDtl.Idj
)
And make sure the rows that are returned are the ones you actually want
deleted. (Since you didn't give me a table or data to test out, I may have
made a mistake!)
----
Louis Davidson - http://spaces.msn.com/members/drsql/
SQL Server MVP
"Arguments are to be avoided: they are always vulgar and often convincing."
(Oscar Wilde)
"Mark in Miami" <MarkinMiami@.discussions.microsoft.com> wrote in message
news:BE80A9BA-401A-4E73-B4AC-4093F72A6D8B@.microsoft.com...
>I need one other favor. I am trying to delete the detail records from the
> detail table before deleting the header record from the pk table. I have
> put
> together the following SQL. The SELECT statement gets the 2 records I
> need
> from the detail table, but I'm not sure how to pass the ID's to the DELETE
> part of the statement to get id of the details records. I have the
> overall
> statement as a SELECT for now, until I work it all out. I will then
> change
> the SELECT to a DELETE. I have included both versions for your review. I
> would certainly appreciate your assistance. I can give you my phone
> number
> if you'd like to speak in person more about my effort.
> Gratefully,
> Mark
> CODE SAMPLE:
> --
> SELECT *
> FROM jrnDTLGrantManagement AS Tdtl
> WHERE EXISTS
> -->this part gets the 2 records I'm looking for but the above returns 8000
> +
> record
> -->ignoring the criteri below. Am I using the EXISTS incorrectly
> -->TSum.IDJ is the PK below
> -->Tdtl.IDJ is the FK
> (SELECT * FROM jrnGrantManagement AS Tsum
> INNER JOIN jrnDTLGrantManagement AS TDtl2 ON TSum.Idj = TDtl2.Idj
> INNER JOIN mbrInitiative AS TInit ON Tdtl2.Initiative = TInit.ID
> WHERE TInit.ParentH1 = 'CanadianBorder'
> AND CONVERT(CHAR(8),TSum.DateModified,10) = '01-11-06')
> when the above works, I plan to convert it to a DELETE statement as
> follows:
> DELETE jrnDTLGrantManagement
> FROM jrnDTLGrantManagement AS Tdtl
> WHERE EXISTS
> (SELECT * FROM jrnGrantManagement AS Tsum
> INNER JOIN jrnDTLGrantManagement AS TDtl2 ON TSum.Idj = TDtl2.Idj
> INNER JOIN mbrInitiative AS TInit ON Tdtl2.Initiative = TInit.ID
> WHERE TInit.ParentH1 = 'CanadianBorder'
> AND CONVERT(CHAR(8),TSum.DateModified,10) = '01-11-06')
>|||Do what people have told you, then add a REFERENCES.. ON DELETE CASCADE
clause to the referencing table. Also, please learn why rows are not
anythignlike records, and you will not findyourself in this situation
again
--CELKO--
Please post DDL in a human-readable format and not a machine-generated
one. This way people do not have to guess what the keys, constraints,
DRI, datatypes, etc. in your schema are. Sample data is also a good
idea, along with clear specifications.
*** Sent via Developersdex http://www.examnotes.net ***|||I should have mentioned this, but only if it truly makes sense. He might
just be doing some data cleanup, or a one-time thing. I usually don't
suggest using cascade (I assume that the FK was in place) unless you truly
want it to happen with no warning whatsoever (which is not always desired.)
Then you can write this sort of code to execute, as it is basically the same
thing that the FK will do anyhow.
----
Louis Davidson - http://spaces.msn.com/members/drsql/
SQL Server MVP
"Arguments are to be avoided: they are always vulgar and often convincing."
(Oscar Wilde)
"--CELKO--" <remove.jcelko212@.earthlink.net> wrote in message
news:uQy6ZWtFGHA.3100@.tk2msftngp13.phx.gbl...
> Do what people have told you, then add a REFERENCES.. ON DELETE CASCADE
> clause to the referencing table. Also, please learn why rows are not
> anythignlike records, and you will not findyourself in this situation
> again
> --CELKO--
> Please post DDL in a human-readable format and not a machine-generated
> one. This way people do not have to guess what the keys, constraints,
> DRI, datatypes, etc. in your schema are. Sample data is also a good
> idea, along with clear specifications.
>
> *** Sent via Developersdex http://www.examnotes.net ***
detail table before deleting the header record from the pk table. I have pu
t
together the following SQL. The SELECT statement gets the 2 records I need
from the detail table, but I'm not sure how to pass the ID's to the DELETE
part of the statement to get id of the details records. I have the overall
statement as a SELECT for now, until I work it all out. I will then change
the SELECT to a DELETE. I have included both versions for your review. I
would certainly appreciate your assistance. I can give you my phone number
if you'd like to speak in person more about my effort.
Gratefully,
Mark
CODE SAMPLE:
--
SELECT *
FROM jrnDTLGrantManagement AS Tdtl
WHERE EXISTS
-->this part gets the 2 records I'm looking for but the above returns 8000 +
record
-->ignoring the criteri below. Am I using the EXISTS incorrectly
-->TSum.IDJ is the PK below
-->Tdtl.IDJ is the FK
(SELECT * FROM jrnGrantManagement AS Tsum
INNER JOIN jrnDTLGrantManagement AS TDtl2 ON TSum.Idj = TDtl2.Idj
INNER JOIN mbrInitiative AS TInit ON Tdtl2.Initiative = TInit.ID
WHERE TInit.ParentH1 = 'CanadianBorder'
AND CONVERT(CHAR(8),TSum.DateModified,10) = '01-11-06')
when the above works, I plan to convert it to a DELETE statement as follows:
DELETE jrnDTLGrantManagement
FROM jrnDTLGrantManagement AS Tdtl
WHERE EXISTS
(SELECT * FROM jrnGrantManagement AS Tsum
INNER JOIN jrnDTLGrantManagement AS TDtl2 ON TSum.Idj = TDtl2.Idj
INNER JOIN mbrInitiative AS TInit ON Tdtl2.Initiative = TInit.ID
WHERE TInit.ParentH1 = 'CanadianBorder'
AND CONVERT(CHAR(8),TSum.DateModified,10) = '01-11-06')You should be able to accomplish this by creating a relationship with
"Cascade Delete Related Fields" selected.
This should let the database handle the deletes in the detail table
automatically when a record from the PK table is deleted. This requires no
coding, just point and click.
That said, if you really want to do it this way, here are a couple of
suggestions...
First, replace the * in your exists select with a litteral 1. I'm not
certain how SQL Server handles this, btu when I worked with Oracle selecting
1 rather than fields was less overhead, as no data had to actually be placed
in memory save the one. If anyone knows if this really makes a difference
or not, I would love to knwo for sure.
It looks like the problem with your exists is that you are not joining it to
your table in your select statement, so it is finding one row exists
regardless of which row you are looking at in the main select. Try adding a
criteria to your exists where it joins to the outer select (delete).
where TDtl2.Idj = TDtl.Idj
You could also make your exists an in clause, and select TDtl2.Idj in place
of *. Then just chang "where exists" to "where TDtl.Idj in" I'm not sure
how this will affect performance as I dont know your table structures.
Hope this helps.
"Mark in Miami" <MarkinMiami@.discussions.microsoft.com> wrote in message
news:BE80A9BA-401A-4E73-B4AC-4093F72A6D8B@.microsoft.com...
> I need one other favor. I am trying to delete the detail records from the
> detail table before deleting the header record from the pk table. I have
put
> together the following SQL. The SELECT statement gets the 2 records I
need
> from the detail table, but I'm not sure how to pass the ID's to the DELETE
> part of the statement to get id of the details records. I have the
overall
> statement as a SELECT for now, until I work it all out. I will then
change
> the SELECT to a DELETE. I have included both versions for your review. I
> would certainly appreciate your assistance. I can give you my phone
number
> if you'd like to speak in person more about my effort.
> Gratefully,
> Mark
> CODE SAMPLE:
> --
> SELECT *
> FROM jrnDTLGrantManagement AS Tdtl
> WHERE EXISTS
> -->this part gets the 2 records I'm looking for but the above returns 8000
+
> record
> -->ignoring the criteri below. Am I using the EXISTS incorrectly
> -->TSum.IDJ is the PK below
> -->Tdtl.IDJ is the FK
> (SELECT * FROM jrnGrantManagement AS Tsum
> INNER JOIN jrnDTLGrantManagement AS TDtl2 ON TSum.Idj = TDtl2.Idj
> INNER JOIN mbrInitiative AS TInit ON Tdtl2.Initiative = TInit.ID
> WHERE TInit.ParentH1 = 'CanadianBorder'
> AND CONVERT(CHAR(8),TSum.DateModified,10) = '01-11-06')
> when the above works, I plan to convert it to a DELETE statement as
follows:
> DELETE jrnDTLGrantManagement
> FROM jrnDTLGrantManagement AS Tdtl
> WHERE EXISTS
> (SELECT * FROM jrnGrantManagement AS Tsum
> INNER JOIN jrnDTLGrantManagement AS TDtl2 ON TSum.Idj = TDtl2.Idj
> INNER JOIN mbrInitiative AS TInit ON Tdtl2.Initiative = TInit.ID
> WHERE TInit.ParentH1 = 'CanadianBorder'
> AND CONVERT(CHAR(8),TSum.DateModified,10) = '01-11-06')
>|||DELETE jrnDTLGrantManagement
FROM jrnDTLGrantManagement AS Tdtl
WHERE EXISTS
(SELECT * FROM jrnGrantManagement AS Tsum
INNER JOIN mbrInitiative AS TInit ON Tdtl2.Initiative = TInit.ID
WHERE TInit.ParentH1 = 'CanadianBorder'
AND CONVERT(CHAR(8),TSum.DateModified,10) = '01-11-06'
)
This makes it a correlated subquery, and should work. First of course,
check my work by executing:
SELECT Tdtl.*
FROM jrnDTLGrantManagement AS Tdtl
WHERE EXISTS
(SELECT * FROM jrnGrantManagement AS Tsum
INNER JOIN jrnDTLGrantManagement AS TDtl2 ON TSum.Idj = TDtl2.Idj
INNER JOIN mbrInitiative AS TInit ON Tdtl2.Initiative = TInit.ID
WHERE TInit.ParentH1 = 'CanadianBorder'
AND CONVERT(CHAR(8),TSum.DateModified,10) = '01-11-06'
AND TSum.Idj = TDtl.Idj
)
And make sure the rows that are returned are the ones you actually want
deleted. (Since you didn't give me a table or data to test out, I may have
made a mistake!)
----
Louis Davidson - http://spaces.msn.com/members/drsql/
SQL Server MVP
"Arguments are to be avoided: they are always vulgar and often convincing."
(Oscar Wilde)
"Mark in Miami" <MarkinMiami@.discussions.microsoft.com> wrote in message
news:BE80A9BA-401A-4E73-B4AC-4093F72A6D8B@.microsoft.com...
>I need one other favor. I am trying to delete the detail records from the
> detail table before deleting the header record from the pk table. I have
> put
> together the following SQL. The SELECT statement gets the 2 records I
> need
> from the detail table, but I'm not sure how to pass the ID's to the DELETE
> part of the statement to get id of the details records. I have the
> overall
> statement as a SELECT for now, until I work it all out. I will then
> change
> the SELECT to a DELETE. I have included both versions for your review. I
> would certainly appreciate your assistance. I can give you my phone
> number
> if you'd like to speak in person more about my effort.
> Gratefully,
> Mark
> CODE SAMPLE:
> --
> SELECT *
> FROM jrnDTLGrantManagement AS Tdtl
> WHERE EXISTS
> -->this part gets the 2 records I'm looking for but the above returns 8000
> +
> record
> -->ignoring the criteri below. Am I using the EXISTS incorrectly
> -->TSum.IDJ is the PK below
> -->Tdtl.IDJ is the FK
> (SELECT * FROM jrnGrantManagement AS Tsum
> INNER JOIN jrnDTLGrantManagement AS TDtl2 ON TSum.Idj = TDtl2.Idj
> INNER JOIN mbrInitiative AS TInit ON Tdtl2.Initiative = TInit.ID
> WHERE TInit.ParentH1 = 'CanadianBorder'
> AND CONVERT(CHAR(8),TSum.DateModified,10) = '01-11-06')
> when the above works, I plan to convert it to a DELETE statement as
> follows:
> DELETE jrnDTLGrantManagement
> FROM jrnDTLGrantManagement AS Tdtl
> WHERE EXISTS
> (SELECT * FROM jrnGrantManagement AS Tsum
> INNER JOIN jrnDTLGrantManagement AS TDtl2 ON TSum.Idj = TDtl2.Idj
> INNER JOIN mbrInitiative AS TInit ON Tdtl2.Initiative = TInit.ID
> WHERE TInit.ParentH1 = 'CanadianBorder'
> AND CONVERT(CHAR(8),TSum.DateModified,10) = '01-11-06')
>|||Do what people have told you, then add a REFERENCES.. ON DELETE CASCADE
clause to the referencing table. Also, please learn why rows are not
anythignlike records, and you will not findyourself in this situation
again
--CELKO--
Please post DDL in a human-readable format and not a machine-generated
one. This way people do not have to guess what the keys, constraints,
DRI, datatypes, etc. in your schema are. Sample data is also a good
idea, along with clear specifications.
*** Sent via Developersdex http://www.examnotes.net ***|||I should have mentioned this, but only if it truly makes sense. He might
just be doing some data cleanup, or a one-time thing. I usually don't
suggest using cascade (I assume that the FK was in place) unless you truly
want it to happen with no warning whatsoever (which is not always desired.)
Then you can write this sort of code to execute, as it is basically the same
thing that the FK will do anyhow.
----
Louis Davidson - http://spaces.msn.com/members/drsql/
SQL Server MVP
"Arguments are to be avoided: they are always vulgar and often convincing."
(Oscar Wilde)
"--CELKO--" <remove.jcelko212@.earthlink.net> wrote in message
news:uQy6ZWtFGHA.3100@.tk2msftngp13.phx.gbl...
> Do what people have told you, then add a REFERENCES.. ON DELETE CASCADE
> clause to the referencing table. Also, please learn why rows are not
> anythignlike records, and you will not findyourself in this situation
> again
> --CELKO--
> Please post DDL in a human-readable format and not a machine-generated
> one. This way people do not have to guess what the keys, constraints,
> DRI, datatypes, etc. in your schema are. Sample data is also a good
> idea, along with clear specifications.
>
> *** Sent via Developersdex http://www.examnotes.net ***
Subscribe to:
Posts (Atom)