Let us suppose we have a table at the remote DB server. I want to copy the whole table on to the sqlserver of my local machine.
Is there any sql query to do this?
Will I have to create the table schema at my local machine and then copy the table contents from the remote server to my local machine or is there any way to completely copy the table along with its schema on to my local machine?
Let us suppose we have a table at the remote DB server. I want
Share
You can use the linked server and then you can use select * into. But you need to create constraints/indexes on the table afterwards.
Or You create the table first and create any other constraints. You might not want to create the Indexes now. This itself is a big topic itself and it usually depends on table size and how data will be. But if you are copying the same data. I would suggest that you create at least clustered index (if the remote table has clustered index ) and create NC indexes after table is populated.
Then you could do following
1.use insert into using linked server. Use order by on clustered index columns.
2. If you can not use linked servers for whatever reason. Use BCP out to a file from remote server Use order by while bcp’ing out and then bulk insert or BCP in to the local system and again use order clause.
You do not need to use order clause if you have not created clustered index on table before loading it.
Then you can create indexes which you need to have on tables.