简体   繁体   中英

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.

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM