x
login about faq Site discussion (meta-askssc)

Delete data from sql table

I want to delete data from table because of i donot require it.But i want to delete old data from table.Means i want to delete data date wise.

more ▼

asked Oct 28 '11 at 10:26 AM in Default

Tushar Thumar gravatar image

Tushar Thumar
1 2 2 2

I guess the question is not tagged well.

@Tushar Which RDBMS are you using and which version? I am not able to understand TIME_STAMP(binint,null) either. Please elaborate. Thanks.

Oct 31 '11 at 04:07 AM Usman Butt
(comments are locked)
10|1200 characters needed characters left

1 answer: sort voted first

Presumably you have some criteria for determining whether the data is old enough to be deleted? If, for example, it has a CreateDate field that's suitable, then something like:

DELETE FROM myTable
WHERE CreateDate < DateAdd(y, -10, getdate())

This will remove all items from the table myTable which were created more than 10 years ago.

more ▼

answered Oct 28 '11 at 12:02 PM

ThomasRushton gravatar image

ThomasRushton ♦
29.1k 6 9 36

Hi,

Thanks for you reply

But my date format is TIME_STAMP(binint,null) and output is like as below.

1319415841689 1319529791610 1319370853868 1319370853930 1319370853946 1319370853977 1319370854024 1319370854040 1319370854071 1319370854133 1319370854149 1319370854180

Oct 29 '11 at 04:31 AM Tushar Thumar

then find the value of the timestamp column that is the last row that you want to remove and use that in the WHERE clause instead of the CREATEDATE that is in this answer.

Oct 29 '11 at 08:09 AM Fatherjack ♦♦

Nullable timestamp? That's worrying.

Oct 30 '11 at 01:28 AM ThomasRushton ♦
(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments



Facebook logo Follow Ask SSC on Facebook
Find Ask SSC on Google+
linkedin logo Find us on LinkedIn

Topics:

x43
x41

asked: Oct 28 '11 at 10:26 AM

Seen: 513 times

Last Updated: Oct 28 '11 at 10:26 AM

Copyright © 2002-2012 Simple Talk Publishing. All Rights Reserved. If you have any queries, please contact the site administrators.
Ask SQL Server Central is a community service provided by Red Gate.