Sql-server – How to create a table in a database on a different server

sql servertable

I need to create Table B in database B on SQL Server B by querying Table A in database A on SQL Server A. Table B does not exist in database B. SQL Server A and B are linked. I wonder how could this be done?

Thanks

Best Answer

You can easily achieve this using OPENROWSET.

Connect on SQL Server B;

SELECT * 
INTO TABLE_B
FROM OPENROWSET('SQLOLEDB', 'server=ServerA;uid=Login;pwd=Password;database=Database_A',
'set nocount on  
SELECT * FROM TABLE_A;
')