How can a LEFT OUTER JOIN return more records than exist in the left table?

I have a very basic LEFT OUTER JOIN to return all results from the left table and some additional information from a much bigger table. The left table contains 4935 records yet when I LEFT OUTER JOIN it to an additional table the record count is significantly larger. As far as I’m aware it is … Read more

Turn off constraints temporarily (MS SQL)

I’m looking for a way to temporarily turn off all DB’s constraints (eg table relationships). I need to copy (using INSERTs) one DB’s tables to another DB. I know I can achieve that by executing commands in proper order (to not break relationships). But it would be easier if I could turn off checking constraints … Read more

What are the main performance differences between varchar and nvarchar SQL Server data types?

I’m working on a database for a small web app at my school using SQL Server 2005. I see a couple of schools of thought on the issue of varchar vs nvarchar: Use varchar unless you deal with a lot of internationalized data, then use nvarchar. Just use nvarchar for everything. I’m beginning to see … Read more

SQL Server query to find all permissions/access for all users in a database

I would like to write a query on a sql 2008 that will report all the users that have access to a specific database, or objects within the database such as tables, views, and stored procedures, either directly or due to roles, etc. This report would be used for security auditing purposes. Not sure if … Read more

How do I check if a Sql server string is null or empty

I want to check for data, but ignore it if it’s null or empty. Currently the query is as follows… Select Coalesce(listing.OfferText, company.OfferText, ”) As Offer_Text, from tbl_directorylisting listing Inner Join tbl_companymaster company On listing.company_id= company.company_id But I want to get company.OfferText if listing.Offertext is an empty string, as well as if it’s null. What’s … Read more

How can I solve a connection pool problem between ASP.NET and SQL Server?

The last few days we see this error message in our website too much: “Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached.” We have not changed anything in our code in a … Read more