Transfer data from one database to another database

后端 未结 9 1890
眼角桃花
眼角桃花 2020-11-28 20:59

How to fetch the data from one database and insert in to another database table? I can\'t to do this. Please help me in transferring data from one to another.

9条回答
  •  南笙
    南笙 (楼主)
    2020-11-28 21:26

    This can be achieved by a T-SQL statement, if you are aware that FROM clause can specify database for table name.

    insert into database1..MyTable
    select from database2..MyTable
    

    Here is how Microsoft explains the syntax: https://docs.microsoft.com/en-us/sql/t-sql/queries/from-transact-sql?view=sql-server-ver15

    If the table or view exists in another database on the same instance of SQL Server, use a fully qualified name in the form database.schema.object_name.

    schema_name can be omitted, like above, which means the default schema of the current user. By default, it's dbo.

    Add any filtering to columns/rows if you want to. Be sure to create any new table before moving data.

提交回复
热议问题