Skip to content
Fix Code Error

Copy tables from one database to another in SQL Server

March 13, 2021 by Code Error
Posted By: RyanKeeter

I have a database called foo and a database called bar. I have a table in foo called tblFoobar that I want to move (data and all) to database bar from database foo. What is the SQL statement to do this?

Solution

On SQL Server? and on the same database server? Use three part naming.

INSERT INTO bar..tblFoobar( *fieldlist* )
SELECT *fieldlist* FROM foo..tblFoobar

This just moves the data. If you want to move the table definition (and other attributes such as permissions and indexes), you’ll have to do something else.

Answered By: David B

Related Articles

  • How do I include certain conditions in SQL Count
  • SQL query return data from multiple tables
  • Android Gradle plugin 0.7.0: "duplicate files during…
  • How to prevent scrolling the whole page?
  • What is the copy-and-swap idiom?
  • What is your most productive shortcut with Vim?
  • Ukkonen's suffix tree algorithm in plain English
  • data.table vs dplyr: can one do something well the…
  • How do SO_REUSEADDR and SO_REUSEPORT differ?
  • TS: How to extract keys from an interface and create…
  • T-SQL How to create tables dynamically in stored procedures?
  • How do I keep only the first map and when the game…
  • Operand type clash: int is incompatible with date +…
  • Usage of __slots__?
  • Three.js: Cannot display mesh created with texture array
  • Database development mistakes made by application developers
  • How does PHP 'foreach' actually work?
  • How to UPSERT (MERGE, INSERT ... ON DUPLICATE…
  • Error message "Forbidden You don't have permission…
  • What is the origin of foo and bar?
  • What is the optimal algorithm for the game 2048?
  • How to change the color of vaadin-select-text-field…
  • What is The Rule of Three?
  • What's the difference between eval, exec, and compile?
  • java.sql.SQLException: - ORA-01000: maximum open…
  • Improve INSERT-per-second performance of SQLite
  • What's the difference between a temp table and table…
  • The definitive guide to form-based website authentication
  • Vue-router: redirect to route if user does not have…
  • Cordova: How to move file to the Download folder?
  • What is move semantics?
  • When should I use a table variable vs temporary…
  • How do I remove single children in a tree?
  • typescript - cloning object
  • Creating an index on a table variable
  • For-each over an array in JavaScript
  • ExpressJS How to structure an application?
  • What does "Fatal error: Unexpectedly found nil while…
  • Drop all the tables, stored procedures, triggers,…
  • sql query to find priority jobs
  • I want to create a SQLite database like in the…
  • How to make onClick card to move to another page in react
  • How should a model be structured in MVC?
  • SecurityException: Permission denied (missing…
  • Pivoting a defined number of rows into columns…
  • Is it possible to add additional property to to…
  • Howto: Clean a mysql InnoDB storage engine?
  • Android 6.0 multiple permissions
  • Why not use tables for layout in HTML?
  • How do I count unique visitors to my site?
  • SQL syntax error when executing MySQL script using…
  • INNER JOIN vs LEFT JOIN performance in SQL Server
  • How to replace values at specific indexes of a python list?
  • How to set up file permissions for Laravel?
  • SQL Server query to find all permissions/access for…
  • Generate SQL Create Scripts for existing tables with Query
  • How to set HTML5 required attribute in Javascript?
  • How can I manually compile a svelte component down…
  • What are the undocumented features and limitations…
  • Why does C++ code for testing the Collatz conjecture…
  • Difference between variable declaration syntaxes in…
  • What's the best way of scraping data from a website?
  • How to take MySQL database backup using MySQL Workbench?
  • Start redis-server with config file
  • Checkout another branch when there are uncommitted…
  • How to check if a table exists in a given schema
  • "Large data" workflows using pandas
  • How to create own inheritable class with underscore
  • SSH Private Key Permissions using Git GUI or…
  • How do I correctly clone a JavaScript object?
  • How do I combine 2 select statements into one?
  • List changes unexpectedly after assignment. How do I…
  • XMLHttpRequest cannot load ✘✘✘ No…
  • Enum Naming Convention - Plural
  • What is an optional value in Swift?
  • Naming Classes - How to avoid calling everything a…
  • Knight's tour Problem - storing the valid moves then…
  • webpack definePlugin failed
  • java.sql.SQLException: Missing IN or OUT parameter…
  • Dynamically allocating an array of objects
  • Copy a variable's value into another
  • How to create a temporary table in SSIS control flow…
  • What does a "Cannot find symbol" or "Cannot resolve…
  • What does T&& (double ampersand) mean in C++11?
  • Log record changes in SQL server in an audit table
  • Multiple separate IF conditions in SQL Server
  • Logging best practices
  • Backgrid filter not working in backbone app
  • Start / Stop a Windows Service from a…
  • How do I execute multiple SQL Statements in Access'…
  • What's the difference between TRUNCATE and DELETE in SQL
  • C++ OpenGL stb_image.h errors
  • Can not connect to local PostgreSQL
  • How to filter a RecyclerView with a SearchView
  • How to speed up insertion performance in PostgreSQL
  • Is there a way to have a switch statement for an…
  • Using underscore.js to copy backbone.js Model…
  • Why do we use __init__ in Python classes?
  • "Thinking in AngularJS" if I have a jQuery background?
  • how to show progress bar(circle) in an activity…

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

How to access the ith column of a NumPy multidimensional array?

Next Post:

Twitter Bootstrap Form File Element Upload Button

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

.net ajax android angular arrays aurelia backbone.js bash c++ css dataframe ember-data ember.js excel git html ios java javascript jquery json laravel linux list mysql next.js node.js pandas php polymer polymer-1.0 python python-3.x r reactjs regex sql sql-server string svelte typescript vue-component vue.js vuejs2 vuetify.js

  • you shouldn’t need to use z-index
  • No column in target database, but getting “The schema update is terminating because data loss might occur”
  • Angular – expected call-signature: ‘changePassword’ to have a typedeftslint(typedef)
  • trying to implement NativeAdFactory imports deprecated method by default in flutter java project
  • What should I use to get an attribute out of my foreign table in Laravel?
© 2022 Fix Code Error