Using “SELECT INTO” with Azure SQL to copy data from another DB

后端 未结 2 1519
隐瞒了意图╮
隐瞒了意图╮ 2021-01-19 09:38

I\'m trying to automate the initialising of a SQL DB on Azure. For some (lookup) tables, data needs to be copied from a source DB into the new DB each time it is initialised

2条回答
  •  旧巷少年郎
    2021-01-19 10:15

    It looks like you might need to define that external table, according to what appears to be the correct syntax:

    CREATE EXTERNAL TABLE [dbo].[source_table](
    ...
    )
    WITH
    (
    DATA_SOURCE = source_db_name
    );
    

    The three part name approach is unsupported, except through elastic database query.

    Now, since you're creating an external table, the query can pretend the external table is an object native to our [target_db]- this allows you to write the query SELECT * FROM [my_table_name], as you figured out from your edits. From the documentation, it is important to note that "This allows for read-only querying of remote databases." So, this table object is not writable, but your question only mentioned reading from it to populate a new table.

提交回复
热议问题