标签:
Importing data into a SQL Server database isn‘t really that tricky: there‘s a straightforward wizard that you can follow to get information from Microsoft Excel, Access and even text files. But what if you want to perform the same import of data on a regular basis? Having to go through the wizard on a weekly, daily, or even hourly basis could become very tedious very quickly!
Fortunately, there‘s a way to set up a scheduled data import in SQL Server meaning that you don‘t have to go through the same process each time you want to import a set of data. There are two main steps involved in this process:
The first step in this process is launching the wizard that is used to import data. To do this:
Choose this option to start the import wizard.
The next part of this blog series explains the steps to follow in the import wizard in order to create an SSIS package.
Once you have opened the import wizard there are several steps to follow in order to create an SSIS package. This part of the series explains what you need to do.
Before we get started, if you‘ve opened the wizard and you see a welcome message, just click Next to get to the useful part!
If you see this message, just click Next.
The first real step of the wizard asks you where your data comes from.
Tell the wizard where your data is stored. The numbered steps are explained below.
如果出现如下错误:
TITLE: SQL Server Import and Export Wizard
The operation could not be completed.
ADDITIONAL INFORMATION: The ‘Microsoft.ACE.OLEDB.12.0‘ provider is not registered on the local machine. (System.Data)
需要下载组件:https://www.microsoft.com/en-us/download/details.aspx?id=23734
The next step is to tell the wizard which database you want the data to be imported to.
Specify where the data should go when it is imported. The numbered steps are explained below.
If you chose to save the package in the previous step you can specify the name and location here.
Save the SSIS package according to the options you select here.
The final step summarises the choices you have made and simply asks to you to confirm everything you have done by clicking Finish at the bottom of the dialog box.
Simply click Finish to confirm the settings you have applied.
If everything works properly you should see a list of tasks being performed in a separate dialog box.
Success! Now all you need to do is click Close.
You can view your SSIS package in one of two different ways, depending on whether you saved it as part of your computer‘s file system or on the SQL Server.
If the package is saved as a file on your computer you can simply browse for it in a Windows Explorer window.
The file will have a dtsx extension.
In order to view a package saved in SQL Server you must first connect to an SSIS server:
Click Connect at the top of the Object Explorer window and choose Integration Services...
需要使用Run As管理员才能打开
You will be able to see your SSIS package by expanding the sequence of folders shown below:
The SSIS package that we created earlier is shown here.
You can even run the package by right-clicking on it and choosing Run Package.
Simply click Execute to run the import steps you saved earlier.
In this step you can specify exactly which data you want to import from the data source you selected in step 1.
Here we‘re going to select all of the data from the Excel spreadsheet, rather than write a separate query to get the data. Click Next to move on to the next step.
This step lets you choose which tables the data you are importing will end up in, and also what should happen to the existing data in those tables.
Choose what will be imported and where it will be imported to. The numbered steps are described below.
Use this dialog box to customise the individual fields in the imported data.
In this step you can choose whether to run the import immediately or to save the import steps for use later on.
Choose when you want the import to happen.
The final step summarises the choices you have made and simply asks to you to confirm everything you have done by clicking Finish at the bottom of the dialog box.
Simply click Finish to confirm the settings you have applied.
If everything works properly you should see a list of tasks being performed in a separate dialog box.
Success! Now all you need to do is click Close.
You can view your SSIS package in one of two different ways, depending on whether you saved it as part of your computer‘s file system or on the SQL Server.
If the package is saved as a file on your computer you can simply browse for it in a Windows Explorer window.
The file will have a dtsx extension.
In order to view a package saved in SQL Server you must first connect to an SSIS server:
Click Connect at the top of the Object Explorer window and choose Integration Services...
You will be able to see your SSIS package by expanding the sequence of folders shown below:
The SSIS package that we created earlier is shown here.
You can even run the package by right-clicking on it and choosing Run Package.
Simply click Execute to run the import steps you saved earlier.
The final stage of this blog series is to create a scheduled job to execute the SSIS package on a regular basis.
You can schedule jobs using the SQL Server Agent. You should find this at the bottom of the list of objects in any database server that you‘ve connected to in SQL Server Management Studio:
The SQL Server Agent appears at the bottom of the list of objects in a database server.
To create a new job using SQL Server Agent:
Right-click the Jobs folder and choose New Job...
You can then use the dialog box to set up the job you want to create. The steps we need to follow in order to schedule our SSIS package execution are described below.
The first step is to give the new job a sensible name, as shown below:
In the General category, enter a descriptive name for the job.
Next, you can create the steps that will make up the job. Our job should have only one step and here‘s how to create it:
Build a list of steps for the job using this page of the dialog box.
Use this dialog box to specify the settings for this job step.
The job should now consist of a single step:
Our entire job consists of a single step, but we could always add more to this by clicking the New...button at the bottom of the dialog box.
To ensure that the job runs at a specific time you need to specify the schedule for the job. To do this:
Use this page to set up the job schedule.
The options in this page of the dialog box are self-explanatory. The options we have selected here ensures the job will be carried out each week at 9am on a Monday morning.
When you have finished applying all of the settings listed above, you can create the job by simply clicking OK on the New Job dialog box.
Your new job will appear in the Jobs folder within SQL Server Agent.
标签:
原文地址:http://www.cnblogs.com/batter152/p/5955898.html