Problem:
You have 2 tables that you would like to compare at the column level (retrieve a list of the columns with different data types and/or names).
It happened to me today and the tables had 100+ columns so...
Alternative 1:
if the tables have the same names and a primary key , you can use one hidden gem of SQL Server (since version 90) called tablediff.exe .
Alternative 2:
My problem is the following , both tables belong to the same schema but hold different names. One of the tables is a simple import table (used to import text files) and has no primary key. Archiving the data from the import table to the destination table fails due a potential data truncation.
For the sake of the example I will a use a database called TestDb that have 2 tables : books and books 1.
As you can see here the only difference is the BookTitle field that has a different length.
Run the following query :
The except statement will select (without duplicates) the elements contained in the left table that are not present in the right table (here books1)
here is the result:
Rgds.
Monday, November 26, 2012
Thursday, October 18, 2012
SSIS Error Code DTS_E_OLEDB_EXCEL_NOT_SUPPORTED
just published "another ssis package" on one of our servers runnig Windows 2008R2.
Go the following error :
the fact is using 64bits you cannot use Microsoft.JET.OLEDB.4.0.
To work around this open the job step properties ans choose the execution option tab.
here is its , now you can you Jet Oledb for excel without issue !
Go the following error :
Description: SSIS Error Code DTS_E_OLEDB_EXCEL_NOT_SUPPORTED: The Excel Connection Manager is not supported in the 64-bit version of SSIS, as no OLE DB provider is available. End Error Error: 2012-10-18 15:43:10.76 Code: 0xC00291EC Source: create xls file for Execute SQL Task Description: Failed to acquire connection "DestinationConnectionExcel". Connection may not be configured correctly or you may not have the right permissions on this connection. End Error DTExec: The package execution returned DTSER_FAILURE (1). Started: 15:43:08 Finished: 15:43:10 Elapsed: 2.309 seconds. The package execution failed. The step failed.
the fact is using 64bits you cannot use Microsoft.JET.OLEDB.4.0.
To work around this open the job step properties ans choose the execution option tab.
then check the following option below left of the properties window.
SQL Template to delete SQL job, maintenance plan and schedule
Problem:
on our test servers , or servers that used to be managed by third party companies, the sql job list can become ...messy.
I came with a SQL server template to delete the job, the maintenance plan and the schedule if unused.
1. Create the template:
open the "view Template" window:
the template menu appears by default at the right of the SSMS window.
Create a folder of you choice in the Template explorer list , right click and choose "new template"
Name the template as you wish , right click the template and choose "Edit".
2. Now copy the code that you can download from here
within the code you will notice special strings , these are the template parameters :
3.Save the template
4. Using the template:
Create a new query on the server on which you want to run the template.
Then simply drag the template you just saved on the blank query window
The template code is then copied on the new query window.
Then here is the cool stuff: click on CTRL+SHIFT+M and you will be prompted to enter the parameters:
The first parameter is to specify the job name, the second parameter (Delete_Maintenance_plan) should be set to 1 if you want to delete the associated maintenance plan. Of course this is only a simple script, error check should be added to check if there is actually a maintenance plan etc..
Nonetheless it is still useful, and shows the basics of using templates.
on our test servers , or servers that used to be managed by third party companies, the sql job list can become ...messy.
I came with a SQL server template to delete the job, the maintenance plan and the schedule if unused.
1. Create the template:
open the "view Template" window:
the template menu appears by default at the right of the SSMS window.
Create a folder of you choice in the Template explorer list , right click and choose "new template"
Name the template as you wish , right click the template and choose "Edit".
2. Now copy the code that you can download from here
within the code you will notice special strings , these are the template parameters :
3.Save the template
4. Using the template:
Create a new query on the server on which you want to run the template.
Then simply drag the template you just saved on the blank query window
The template code is then copied on the new query window.
Then here is the cool stuff: click on CTRL+SHIFT+M and you will be prompted to enter the parameters:
The first parameter is to specify the job name, the second parameter (Delete_Maintenance_plan) should be set to 1 if you want to delete the associated maintenance plan. Of course this is only a simple script, error check should be added to check if there is actually a maintenance plan etc..
Nonetheless it is still useful, and shows the basics of using templates.
Tuesday, October 16, 2012
Free sql online formatter tool
Recently found out this TSQL Formatting tool that is worth sharing : Instant SQL Formatter
Really like it as there are many options, can really save some time and improve readability.
enjoy
Really like it as there are many options, can really save some time and improve readability.
enjoy
sqlmaint.exe failed. [SQLSTATE 42000] (Error 22029)
We still have an SQL 2000 production server from a third party supplier. The backups failed for several days and looking on serveral blogs I found that some had disk space issues.
I did not have a disk space issue BUT a consultant from the third party had restricted the rights of the DATA folder to administrators only !
so if you run into this error :
I did not have a disk space issue BUT a consultant from the third party had restricted the rights of the DATA folder to administrators only !
so if you run into this error :
- check that you have sufficient disk space
- check the data folder security :)
How to select column names of a table
select COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME ='my_table'
Monday, September 10, 2012
SQL Error 7302 Cannot Create linked server for OleDb Provider
Symptoms:
You Create a linked server for an excel or Access file. The following procedure relates to Excel 2003 (Microsoft.Jet.Oledb.4.0) and Excel 2007. (Ace driver – Microsoft Office 12 Access OleDb Provider.
You cannot make the connection and receive the error message “cannot load Microsoft Jet oledb provider for linked server null – SQL Error 7302”.
Note: Do not install MS Office 2007 on a server to connect to Excel or Access 2007 files. Only connectivity tools are needed (ACE Drivers).
If you try to run a select on a worksheet you can see the following message in the Event viewer (Applications):
The machine-default permission settings do not grant Local Activation permission for the COM Server application with CLSID
{2206CDB0-19C1-11D1-89E0-00C04FD7A829}
to the user <user> SID (sid). This security permission can be modified using the Component Services administrative tool.
RESOLUTION
Grant the user permissions to start the COM component. To do this, follow
these steps:
1. Click Start, click Run, type regedit in the Open box, and
then click OK.
2. Locate and then click the following registry subkey:
HKEY_CLASSES_ROOT\CLSID\CLSID value
Note In this subkey, "CLSID value" is a placeholder for the CLSID
information that appears in the message.
3. In the right pane, double-click AppID.
The Edit String dialog box appears. Leave this dialog box open and continue
to the next step.
4. Click Start, click Run, type dcomcnfg in the Open box, and then click OK.
If a Windows Security Alert message prompts you to keep blocking the
Microsoft Management Console program, click to unblock the program.
5. In Component Services, double-click Component Services, double-click
Computers, double-click My Computer, and then click DCOM Config.
6. In the details pane, locate the program by using the friendly name.
If the AppGUID identifier is listed instead of the friendly name, locate the
program by using this identifier.
7. Right-click the program, and then click Properties.
8. Click the Security tab.
9. In the Launch and Activation Permissions area, click Customize, and then
click Edit.
10. Click Add, type the user's account name, and then click OK.
11. While the user is selected, click to select the Allow check boxes for
the following items:
.. Local Launch
.. Remote Launch
.. Local Activation
.. Remote Activation
12. Click OK two times.
13. Quit Registry Editor.
Subscribe to:
Posts (Atom)









