How to Use DELETE and INSERT simultaneously in Query Script

微笑、不失礼 提交于 2020-02-08 10:00:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!