Menu
Either help me to copy the selected rows to another datagridview without a button press(i mean it will copy as soon as a user checks a rows checkbox) When you check datagridview row, this row value will be added into list(of datagridviewrow), then pass this list to another form. One more solution is to run sub query for two time with different updated Datecolumn value. It will select data from same table and updated.
Active3 years, 4 months ago
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?
Christopher Rapcewicz1,38755 gold badges2424 silver badges3737 bronze badges
RyanKeeterRyanKeeter2,78966 gold badges2929 silver badges3939 bronze badges
9 Answers
On SQL Server? and on the same database server? Use three part naming.
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.
Sam Saffron92.6k6969 gold badges291291 silver badges485485 bronze badges
Amy BAmy B91.5k1818 gold badges124124 silver badges168168 bronze badges
SQL Server Management Studio's 'Import Data' task (right-click on the DB name, then tasks) will do most of this for you. Run it from the database you want to copy the data into.
If the tables don't exist it will create them for you, but you'll probably have to recreate any indexes and such. If the tables do exist, it will append the new data by default but you can adjust that (edit mappings) so it will delete all existing data.
I use this all the time and it works fairly well.
Sunil D.17.2k66 gold badges4242 silver badges5959 bronze badges
DavidDavid5,52122 gold badges1515 silver badges44 bronze badges
This should work:
It will not copy constaints, defaults or indexes. The table created will not have a clustered index.
Alternatively you could:
If your destination table exists and is empty.
Sam Saffron92.6k6969 gold badges291291 silver badges485485 bronze badges
leoinfoleoinfo6,25266 gold badges3232 silver badges4646 bronze badges
If it’s one table only then all you need to do is
- Script table definition
- Create new table in another database
- Update rules, indexes, permissions and such
- Import data (several insert into examples are already shown above)
One thing you’ll have to consider is other updates such as migrating other objects in the future. Note that your source and destination tables do not have the same name. This means that you’ll also have to make changes if you dependent objects such as views, stored procedures and other.
Whit one or several objects you can go manually w/o any issues. However, when there are more than just a few updates 3rd party comparison tools come in very handy. Right now I’m using ApexSQL Diff for schema migrations but you can’t go wrong with any other tool out there.
Igor VoplovIgor Voplov
- Script the
create table
in management studio, run that script in bar to create the table. (Right click table in object explorer, script table as, create to...) INSERT bar.[schema].table SELECT * FROM foo.[schema].table
18.2k66 gold badges4242 silver badges5959 bronze badges
ScottStonehouseScottStonehouse20.2k66 gold badges2727 silver badges3333 bronze badges
You can also use the Generate SQL Server Scripts Wizard to help guide the creation of SQL script's that can do the following:
- copy the table schema
- any constraints (identity, default values, etc)
- data within the table
- and many other options if needed
Good example workflow for SQL Server 2008 with screen shots shown here.
ryanryan
You may go with this way: ( a general example )
Also if you need to generate the column names as well to put in insert clause, use:
Copy the result and paste into query window to represent your table column names and even this will exclude the identity column as well:
Remember the script to copy rows will work iff the databases belongs to the same location.
You can Try This.
Server name is optional if both DB is in same server.
![Row Row](/uploads/1/2/5/7/125700635/211418435.png)
12.7k66 gold badges2828 silver badges4848 bronze badges
NeverHopelessNeverHopeless9,89344 gold badges2929 silver badges5252 bronze badges
If there is existing table and we wants to copy only data,we can try this query.
insert into Destination_Existing_Tbl select col1,col2 FROM Source_Tbl
MohanMohan
Arun Prasad E SArun Prasad E S4,62933 gold badges4646 silver badges5656 bronze badges
protected by Community♦Aug 10 '11 at 2:47
Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?
Would you like to answer one of these unanswered questions instead?