HOW TO EXPORT/ IMPORT DB FROM SQL SERVER - sql

I need to export the db including all the tables from SQL Server and then to import it to another computer with SQL Server.
I tried to do:
tasks-> generate scripts
But when I tried to import this db
by attach he doesn't recognize this file.
how should i do it correctly?
we did our project on my friend computer but i want to get it for myself to...

What you tried is to generate the scripts in order to create the database structure (if you want to use these scripts you need to execute them from SQL Management Studio on your other computer). That's a good solution if you only want to create the database structure on another computer.
If you want to restore the database on another computer with all the structure and data of your database, right-click on your database from SQL Management Studio -> Tasks -> Back Up.
After creating a backup of your database you simply need to copy the generated file to another computer and proceed the restore process.
Here is a link that explains the entire process: Create a Full Database Backup
Hope this will help you.

You can use Backup\Restore technique to make exact copy of your database, But like you said, you only want your tables to be transferred so you can use 'SQL Server Import Export Wizard' for the same.
Right Click on db -> tasks -> Export data
Using above option you can store all data into a flat file also and take that flat file to destination and import the same.

Related

Create a local DB and import csv or excel file

Due to circumstances beyond my control, I'm currently not able to create a table on one of my company's databases, and I got a project where I need to break down and get stats from a large data file. I can open it in Excel, but its not very happy about it. What I'd like to be able to do is create a local database where I could use the import wizard to import an excel file to a new table. Is this possible? If so, how would I do it?
SQL server has a free express edition of their database http://www.microsoft.com/en-us/server-cloud/products/sql-server-editions/sql-server-express.aspx. It probably has a cumulative data limit though (Oracle express does, I don't know much about sql server express).

Automating the Export Data Task

I have a database on one server that I need to copy to another server. I can do this manually using the Export Data task, which is fine for a one time export, but I would like to speed this up as it is going to be repeated.
The database will always contain the same set of tables, I just need to get a copy of this database with it's tables and their data from one server to another.
I'd like to create some sort of reusable tool that allows you to specify the source and target database servers and then copies this specific database from one to another. Is this possible?
The Export Data task in SQL 2005 and later uses SQL Server Integration Services (SSIS) under the hood. You can save the package you're already using and run it on a schedule or on demand. You can also edit it (once it is saved) using the Business Intelligence Development Studio (BIDS).
At the end of the Export wizard (on the "Save and Run Package" screen), you can tick the "Save SSIS Package" check-box to store the package either within SQL server or on the file system. The file system is probably simpler.
Once you have the package you can execute it from the command line using the dtexec tool, or from a SQL Agent job using an Execute SSIS task.
SSIS is too big a subject to cover in full here - there are decent tutorials within SQL server books online if you need more details - alternatively, as another SO question if you get stuck.

Import .sql file in Access

I need to import to Access a .sql database backup file created with MySql .
Is there a way to perform this operation?
You can't restore a MySQL backup into any other database system.
If you want to import the MySQL data into Access, you could export it all into CSV files and import those to Access. You will still need to recreate relationships, defaults, indexes (?) and other data.
You can import SQL Server data into a new Access table. In general, importing is a way to convert data from a different format and copy it into Access. The source table or file is not altered in this process. You can import directly from a SQL Server database using an ODBC connection, a text file exported from SQL Server, or an XML file exported from SQL Server.
To make frequent import operations more convenient, you can automate them by creating a macro or creating a Microsoft Visual Basic for Applications (VBA) procedure. This is useful, for example, when you import data on a regular schedule or you have unusual or complex requirements for importing data.
if you use SQL Server Management studio then you can open the .SQL files and it will give you help in figuring out what syntax works in SQL -- and which doesn't.
For example, if you have a table name that is mis-spelled, SQL Server Management Studio will give you red squigglies under that table name.
I don't see that functionality in Access, and I don't think that it's coming any time soon. Access (Jet) hasn't gotten any new features in almost fifteen years.

How to export data from Excel spreadsheet to Sql Server 2008 table

I want to import data from an Excel file - assume Excel 2003 / .xls - to Sql Server 2008.
Have tried adding a linked server to the JET OLE DB Access driver, and of course it fails on the 64-bit machine.
But when I try to drop the linked server while experimenting, there's another error saying that the linked server already/still exists!
I have also tried changing the Excel driver to 32-bit (regedit tool) but am not sure if it's doing anything, same error is coming up!
Some more details:
Say Table1 in Excel file has 5 columns.
I want to map to Database.dbo.Table1 with 5 columns again, but with different names in table.
Is there a way to do even do such an import?
From your SQL Server Management Studio, you open Object Explorer, go to your database where you want to load the data into, right click, then pick Tasks > Import Data.
This opens the Import Data Wizard, which typically works pretty well for importing from Excel. You can pick an Excel file, pick what worksheet to import data from, you can choose what table to store it into, and what the columns are going to be. Pretty flexible indeed.
You can run this as a one-off, or you can store it as a SQL Server Integration Services (SSIS) package into your file system, or into SQL Server itself, and execute it over and over again (even scheduled to run at a given time, using SQL Agent).
Update: yes, yes, yes, you can do all those things you keep asking - have you even tried at least once to run that wizard??
OK, here it comes - step by step:
Step 1: pick your Excel source
Step 2: pick your SQL Server target database
Step 3: pick your source worksheet (from Excel) and your target table in your SQL Server database; see the "Edit Mappings" button!
Step 4: check (and change, if needed) your mappings of Excel columns to SQL Server columns in the table:
Step 5: if you want to use it later on, save your SSIS package to SQL Server:
Step 6: - success! This is on a 64-bit machine, works like a charm - just do it!!
There are several tools which can import Excel to SQL Server.
I am using DbTransfer (http://www.dbtransfer.com/Products/DbTransfer) to do the job.
It's primarily focused on transfering data between databases and excel, xml, etc...
I have tried the openrowset method and the SQL Server Import / Export Assitant before.
But I found these methods to be unnecessary complicated and error prone in constrast to doing it with one of the available dedicated tools.
In SQL Server 2016 the wizard is a separate app. (Important: Excel wizard is only available in the 32-bit version of the wizard!). Use the MSDN page for instructions:
On the Start menu, point to All Programs, point toMicrosoft SQL Server , and then click Import and Export Data.
—or—
In SQL Server Data Tools (SSDT), right-click the SSIS Packages folder, and then click SSIS Import and Export Wizard.
—or—
In SQL Server Data Tools (SSDT), on the Project menu, click SSIS Import and Export Wizard.
—or—
In SQL Server Management Studio, connect to the Database Engine server type, expand Databases, right-click a database, point to Tasks, and then click Import Data or Export data.
—or—
In a command prompt window, run DTSWizard.exe, located in C:\Program Files\Microsoft SQL Server\100\DTS\Binn.
After that it should be pretty much the same (possibly with minor variations in the UI) as in #marc_s's answer.

transfer SQL database (table and data)

iv created a database with some tables and populated them using SQL server 2008, i want to move the database to another machine, what would be the best way copy the database and recreate it in another location ??
by the way im connecting to localhost\SQLEXPRESS if thats important !!
thanks
Backup and restore is usually the simplest way. The only complexity you may encounter is that your may have to recreate and associate users on your target system.
Do a backup of your database and then restore it on another machine
Right click on your database in SSMS. Choose Tasks->Backup. Then choose your location and click ok. Take the backup file you create out of the folder it was in and put it into the same folder on your other computer. Then open SSMS on your other machine. Right click on the database folder and click Restore Database. Enter what you ant to name it, choose From Device and then find your file. Click OK and you are done.
I would use SQL Server backup and restore. I believe you can backup in SQLExpress (you just can't schedule one).
Right click your database, and select Tasks -> Backup. Do the backup.
On your other sql server instance create a database with the same name. And do Tasks -> restore -> database
If you have permissions to restore on the target database server then that is by far the best way to copy the database.
If you don't have permissions, then you'll want to connect to the source and target databases with Management Studio and Import the data from the source. If you have simple primary key only indices on your tables you can import by right clicking on the target database name, then select Tasks, then Import Data. A wizard will walk you through it.
You can practice by importing the data into a new database on your local machine first.
If you have more complex indices or functions, sprocs, and views, you'll want to create the new database first, before you import the data. Same procedure, but select Generate Scripts. The wizard will walk you through the necessary steps. Under script options you'll want to make sure you select True for Script Indexes.
Again you can practice by recreating and importing locally. Though if you create locally you'll need to give the database a new name.