x

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, 2011 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, 2011 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, 2011 at 12:02 PM

ThomasRushton gravatar image

ThomasRushton ♦
33.9k 18 20 44

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, 2011 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, 2011 at 08:09 AM Fatherjack ♦♦
Nullable timestamp? That's worrying.
Oct 30, 2011 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.

New code box

There's a new way to format code on the site - the red speech bubble logo will automatically format T-SQL for you. The original code box is still there for XML, etc. More details here.

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

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x52
x46

asked: Oct 28, 2011 at 10:26 AM

Seen: 944 times

Last Updated: Oct 28, 2011 at 10:26 AM