Which of the join and subquery queries would be faster and why? When I should prefer one over the other?

Well, I believe it’s an “Old but Gold” question. The answer is: “It depends!”. The performances are such a delicate subject that it would be too much silly to say: “Never use subqueries, always join”. In the following links, you’ll find some basic best practices that I have found to be very helpful: Optimizing Subqueries … Read more

Creating table variable in SQL server 2008 R2

@tableName Table variables are alive for duration of the script running only i.e. they are only session level objects. To test this, open two query editor windows under sql server management studio, and create table variables with same name but different structures. You will get an idea. The @tableName object is thus temporary and used … Read more

SQL Server Profiler: Templates not showing / missing

I have managed to resolve the issue, I solved it by following this link’s suggestion: http://www.mattbutton.com/2011/06/01/sql-profiler-templates-missing/ The following comes from the link: If you are connecting to a SQL server with the SQL profiler and none of your templates are showing up, compare the versions of the SQL profiler you are running and the version … Read more

How to delete from source using MERGE command in SQL Server 2008?

You can use the output clause to capture the modified/inserted rows to a table variable and use that with a delete statement after the merge. DECLARE @T TABLE(EmployeeID INT); MERGE Target1 AS T USING Source1 AS S ON (T.EmployeeID = S.EmployeeID) WHEN NOT MATCHED BY TARGET AND S.EmployeeName LIKE ‘S%’ THEN INSERT(EmployeeID, EmployeeName) VALUES(S.EmployeeID, S.EmployeeName) … Read more

GRANT syntax for domain\user

Assuming you have created a user in this database associated with the AD login, e.g. CREATE LOGIN [domain\user] FROM WINDOWS; GO USE your_database; GO CREATE USER [domain\user] FROM LOGIN [domain\user]; GO Then you merely have to follow the same syntax. Because \ is not a standard character for an identifier, you need to escape the … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)