Skip to content
Advertisement

How to select insert from a table in SQL server with a where condition of a column time_stamp?

I have a table audit_records with column time_stamp as datatime2 and I would like to insert all records which has time_stamp value greater than 2019-01-01 00:00:00.0000000 into a new table audit_records_current.

This because the table has over 75 million rows and I would like to delete this table after moving the rows newer than time_stamp 2019-01-01 00:00:00.0000000.

Advertisement

Answer

You can create a new table called audit_records_current like so:

select *
into audit_records_current
from audit_records
where time_stamp > '2019-01-01 00:00:00.0000000';

Then you can drop audit_records using drop table audit_records;

You have the choice of emptying out audit_records while still keeping the table. If you want to do that, just do truncate table audit_records;

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement