Whenever the column returned by the subquery contains a NULL value, NOT IN will always return an empty set. Filtering out the NULL values in the subquery will solve this problem.
select
*
from
table1
where
col1 not in(select col2 from table2 where col2 is not null)
Read SQL Server: JOIN vs IN vs EXISTS - the logical difference for a detailed explanation.
To keep track of favourite web sites, useful links, articles and own experiences which may be helpful in future software development.
Thursday, July 1, 2010
Monday, June 21, 2010
Corrupt index(es) in msdb
I was trying to delete a SQL Job using sp_delete_job. It continued to fail with the message:
(The command that fixed it is DBCC CHECKDB('msdb', REPAIR_REBUILD), but there is quite a bit of preparation that needs to be done before this command will execute successfully. See the blog post I referred to.)
Unable to find index entry in index ID 1, of table {object_id of table}, in database 'msdb'. The indicated index is corrupt or there is a problem with the current update plan. Run DBCC CHECKDB or DBCC CHECKTABLE. If the problem persists, contact product support.I found this blog post and the script in it repaired the msdb.
(The command that fixed it is DBCC CHECKDB('msdb', REPAIR_REBUILD), but there is quite a bit of preparation that needs to be done before this command will execute successfully. See the blog post I referred to.)
Thursday, June 17, 2010
LocalSystem, LocalService and NetworkService Accounts
Below are links to resources which help explain the difference between these accounts:
This one about "Understanding the Local Service and Network Service Accounts" was the most useful.
Click here for the MSDN article in this regard.
This one about "Understanding the Local Service and Network Service Accounts" was the most useful.
Click here for the MSDN article in this regard.
Tuesday, June 8, 2010
Cannot connect to a remote SQL Server instance using SSMS on a Windows 7 pc
I had the following problem: On my Windows XP pc I could use SQL Server 2008 SSMS to connect to our SQL Server 2005 production server, but when I tried to connect from my (newly setup) Windows 7 pc I got the following error:
To resolve the problem I did the following on my Windows 7 pc:
* Opened Windows Firewall
* Opened the "Allow a program or feature through Windows Firewall" page
* Clicked "Allow another program..."
* Selected "SQL Server Management Studio" and clicked "Add". Only Domain was checked.
* Clicked "OK".
Cannot connect to {SQL Server Instance Name}.
Additional information:
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified) (Microsoft SQL Server)
To resolve the problem I did the following on my Windows 7 pc:
* Opened Windows Firewall
* Opened the "Allow a program or feature through Windows Firewall" page
* Clicked "Allow another program..."
* Selected "SQL Server Management Studio" and clicked "Add". Only Domain was checked.
* Clicked "OK".
Labels:
SQL Server Management Studio,
SSMS,
Windows Firewall
Tuesday, February 23, 2010
Don't be greedy in T-SQL queries
I am working on improving the performance of some stored procedures. The queries all make use of index seeks and index scans to get to the data, so, nothing I can improve there.
The procs call other procs which call some more procs. A join to a large table (+/-2million records) gets repeated in several of these procs.
So, I changed the deepest nested proc to return all the data which will be needed by the other procs. I removed the repeated join; and the performance problem is solved.
So, two very important tips for performance tuning queries:
The procs call other procs which call some more procs. A join to a large table (+/-2million records) gets repeated in several of these procs.
So, I changed the deepest nested proc to return all the data which will be needed by the other procs. I removed the repeated join; and the performance problem is solved.
So, two very important tips for performance tuning queries:
- Only return the records you are interested in; and
- Only touch a record once if possible.
Tuesday, February 16, 2010
CATCH block not executing after an error in the TRY block
Today we had trouble with the CATCH block in a T-SQL script which did not execute after an error in the TRY block. It turned out that there are times when your TRY block can fail and the CATCH block will get bypassed altogher.
Click here or on the title of this article to see the article by Alexander Kuznetsov about exactly this problem.
Our problem was a compile error: a column name we referenced in a join statement no longer existed.
Click here or on the title of this article to see the article by Alexander Kuznetsov about exactly this problem.
Our problem was a compile error: a column name we referenced in a join statement no longer existed.
Thursday, February 11, 2010
SSIS Indirect Configurations
With indirect configurations SSIS enables you to store the path to the dtsConfig file in an environment variable. At runtime the package looks up the location to the config file, load the config file at that location, and does whatever it needs to do with the information.
If your SSIS package gets executed from a SQL Job, it is important to restart the SQL Agent after creating the environment variable - the SQL Agent caches the environment variables and won't pick up new ones unless restarted.
If your SSIS package gets executed from a SQL Job, it is important to restart the SQL Agent after creating the environment variable - the SQL Agent caches the environment variables and won't pick up new ones unless restarted.
Subscribe to:
Posts (Atom)
SQL Server
- 101 Things I wish you knew about SQL Server
- 102 SQL Server 2005 Tutorials and Articles
- Audit Trails and Logging Part 1 (sqlservercentral.com)
- Audit Trails and Logging Part 2 (sqlservercentral.com)
- Audit data using SQL Server 2005's COLUMNS_UPDATED function
- Calling a web service from a CLR proc
- Choosing between SQL Server Compact 3.5 and SQL Server 2005 Express Edition
- Deploying Database Developments
- Download SQL Server 2005 Express Edition
- Download SQL Server Compact 3.5
- How to return a result set from a SQL Server 2005 CLR stored procedure (mssqltips.com)
- How to return a result set from a SQL Server 2005 CLR stored procedure (mssqltips.com)
- Online Training (sqlservercentral.com)
- SQL Server 2008 Transparent Data Encryption getting started (MSSQLTips.com)
- SQL Server Audit in SQL Server 2008 – Part 1 (Database Journal)
- SQL Server Data Structure
- SQL Server Indexes: The Basics
- T-SQL Enhancement - APPLY Join Operator (drsql)
- T-SQL Ranking Functions (MSDN)
- T-SQL: Calendar tables
- T-SQL: Correlated Joins Using "Apply" (sqlservercentral.com)
- T-SQL: Identify Modified Columns in a Trigger (SQL Server Magazine)
- T-SQL: Identity Columns (simple-talk)
- T-SQL: More with SQL Server 2005 : Top n Per Group, Paging, and Common Table Expressions
- T-SQL: Obtaining Data as XML from SQL Server (MSDN)
- T-SQL: SQL Server 2005 Programmability Enhancements — Common Table Expressions (codeguru)
- T-SQL: SQL Server 2005: Creating User-defined Functions (Database Engine) (MSDN)
- T-SQL: SQL Server: JOIN vs IN vs EXISTS - the logical difference
- T-SQL: The "Numbers" or "Tally" Table: What it is and how it replaces a loop.
- T-SQL: The Curse and Blessings of Dynamic SQL
- T-SQL: The ultimate guide to the datetime datatypes
- T-SQL: Understanding SQL 2005's new PIVOT clause
- T-SQL: Use Dynamic SQL to Improve Query Performance
- T-SQL: Using the OUTPUT clause for practical SQL Server applications
- T-SQL: What's New in FOR XML in Microsoft SQL Server 2005 (MSDN)
- TechNet: Improving Performance with SQL Server 2005 Indexed Views
- The Truth about "Cursor Busting" in SQL
- Thinking Set-Based .... or not?
- Upgrading a Database SQL 2000 to SQL 2005 (sqlservercentral.com)
DTS and SSIS
- Download SQL Server 2005 DTS add-in
- Dynamically Generate Folders for File Output using Variables in SSIS (sqlservercentral.com)
- How to create an XML config file for a SSIS package
- SQL Server Integration Services (SSIS), ETLs and Best Practices (Brian's Blog)
- Transactions in SQL Server 2005 Integration Services