问题
I am using Google BigQuery(Uses Standard SQL) but I have a Table with some data. Based on the data in the Table, I want to insert fake messages rows to that table, and after that, delete all data(the newly inserted fake messages) from that table, But I do worry of deleting all of data within that table . Any examples of how to properly query something like this?
回答1:
If you are worried about accidentally deleting data, I would create a view that combines your actual data with your fake data.
CREATE VIEW project.dataset.my_view
AS
select message from project.dataset.actual_table
UNION ALL
select 'This is a fake message 1' as message
UNION ALL
select 'This is a fake message 2' as message
You can query against this view without changing underlying data, and when you are done, simply delete the view. Much safer than playing around with important data if you aren't crystal clear on what you are doing.
来源:https://stackoverflow.com/questions/60006270/how-to-use-delete-and-insert-simultaneously-in-query-script