How can I copy tables from one SQL Server database to another using Visual Studio 2010 & SQLEXPRESS - sql

I have two *.mdf databases and trying to copy the ASP.NET membership tables from one to the other.
I have tried the data\schema compare tool which I am either not using correctly or it won't find anything to add\update for some reason.
Publish to provider created an sql file with the data and schema. Don't know how I can use it from within VS to pull some tables I need and add to another existing database.
Is there a console or something I can launch a query from for SQL Server Express to copy tables from one of the db's in its DATA directory to another ?
Update: Just used the import/export data wizard. It finally copied all my tables without error but for some reason did not retain the relationship data/foreign keys. The tables that I copied over to the other database did not exist on the database, so no type conflict could arise but it still didn't copy the diagram and relationships.

Is it require to Copy in real time?..i had made code that copy Data from Sqlserver to MySql but it's real time and if you want to copy data not in real time then You Have to Use Migration toolkit.

Related

How do I add records from an Access database into an existing SQL Server database?

I have an existing Access database that has out grown it's usefulness. I have written a Visual Basic program that uses a SQL Server database and have been re-entering the data from the Access file into SQL Server individually.
I still have 300+ records to move and would like to find a way to do all this using either a data snippet in Visual Basic, or using SQL Server Express. I'm smart enough to set up and use Access, and smart enough to create a program and database in Visual Basic and SQL Server but for some reason I not smart enough to move the records between the 2 databases.
When I originally created the .mdf file I attempted to move the records at that time but everything I tried didn't work so I figured I'd get it later, but now I have 300+ records in the .mdf file and need to get the others moved over. Anybody have any ideas?
Easiest thing to do is create your database, then in SSMS's Object Explorer, right click on the database, Tasks -> Import Data ... and go through the Import/Export wizard, selecting MS Access as your source.

Merge Tables between Databases

I would like to move all the rows inside a couple of tables from one SQL Server database into another SQL Server located in a different remote server. This means I cannot connect to both at the same time, so the exchange should have to be done via file or a similar procedure. The tables have identical column definition, meaning it is only the data inside what differs. Also important to note, I do not expect a full overwrite, but rather a merge into the second database.
You can use SQL Management Studios export/import tool. It can extract data in CSV file, so you can save it on a disk, after that change connection to the new server and run import with exported file. This should do a trick.
Here is a nice and quick tutorial:
https://www.youtube.com/watch?v=Vf6pluv0Lv4
Could you create a linked server?
http://msdn.microsoft.com/en-us/library/ff772782.aspx
use SSIS it will be good it can be automated as well as you can change your configurations also . tomorrow if you got different server you just have to change connection strings and if it is a daily task use SSIS .

Creating a blank copy of a SQL Server 2012 database on the same Instance

I'm trying to determine the best way of creating a blank copy of a SQL Server 2012 database, renaming it & placing it on the same server instance. I could restore/rename a backup copy, and then delete all the data, but there are quite a few tables/views, stored procedures, triggers, etc.
Are there any drawbacks with the "generate scripts for database objects" wizard? Just trying to figure out the most efficient way to create a blank copy & would appreciate anyone's experience/wisdom on the topic.
I am running a SQL Server 2012 Enterprise edition. We have a database that our colleagues like, so we are planning to create a copy & populate with their data instead of our data.
Go to Object Explorer ,Right Click the database you want to create a blank copy of.
Right Click --> Tasks --> Generate Scripts
Select the entire Database, you also have the option to select specific objects, In advance option select schema only.
I would prefer this method over any other, as Restoring a Copy of database and then deleting data means doing a lot of work which was never required to begin with. Backing up data that was never required, restoring unwanted data and then finally making sql server to delete it, a lot of unnecessary work.
Another reason why scripts are better over other options, These scripts will use fresh pages to write all of this data. Imagine you having to write something on a brand new note book as compare to a note book where you had to erase first and then use it to write data on it.

Managing a subset of the database in a SQL Server 2008 DB Project

I'm new to using SQL Server 2008 DB Project's in VS 2010. I found a good intro to setting them up. It's nice how they create Tables, Stored Proc's etc as objects. But is it also a limitation?
I want to use this project to manage 1 stored procedure (for learning). I do not want to import the entire database because 90% of the database is stuff we do not manage.
I created a new project without doing the import process. I then added a new stored procedure. Now I am having difficulty getting the thing to build. I'm getting various errors saying that I have unresolved references to objects.
How can I add a new stored procedure..build it and deploy it to the database? Is it possible with this kind of SQL project or do I need to drop back to the old, simple type of SQL projects that VS 2008 and below used?
Update
According to another post, support for the Database Project type is gone. Support for my situation appears to have been erased.
UPDATE 2 3/21/2012
I installed MSSCCI which allows me to use SSMS directly with TFS 2010. I no longer needed and found the setup process to be unmanageable for a large database SQL 2008 project. Especially when you only manage a small % of the DB.
You can Partition a Database Project by Using Partial Projects. This allows the database project to know the entire schema of the database, at the same time, you need not maintain the entire schema. You can work with the subset of the database that's under active development, for instance (or the subset which is your responsibility), yet the project knows the entire schema. This permits it to create change scripts at deployment time, by comparing the schema in the project with the schema in the target database.
You must import all schema objects referenced by your new stored procedure. But this can become a large task because every referenced object need all it's references too.
More trouble with linked server objects.

Using temporary tables to store data from Excel file

I've got a database with information on servers and applications. I also have an Excel file which has some of that information saved in it .
What I'm trying to do is compare the database with the Excel file and output all the results which are present in the DB and not the Excel file, and vice versa.
After some thinking, I decided that it might be best to create temporary tables and save all the data from the Excel file into them, and then do an outer join between the corresponding tables (I'm using SQL Server).
How do I go about doing this without creating models in Rails for them (unless I specifically have to create them)?
Not sure how to use raw SQL in this instance =s
You actually have several choices on how to import the Excel data. If you're looking for a strictly SQL Server solution then you can use a linked server or distributed queries. You can also use DTS/SSIS (depending on your version of SQL Server) for a solution that's external. You could call the SSIS or DTS packages from your own code. Excel also has an OLE DB provider, so if your application uses ADO or otherwise uses OLE DB then you can use that.
All of these methods are explained in a little more detail on Microsoft's website, including some sample code for some of them.