Archive for the ‘SQL’ Category

What to use where or inner join?

Actually, I received a question like this few days ago and if such a question appear to people why not to right the answer here. :)  If you have two queries like those below what do you think is the difference?

1: select count(a.id)

2: from answer a, answerset aset

[...]

EXECUTE permission denied on object ’sp_sdidebug’, database ‘master’, owner ‘dbo’.

An exception that you can get during application  debugging when you attach to an aspnet_wp.exe process. If you use a published web site it is fine but attaching to it in some case can cause this exception to happened. What is the reason? By default the debugger tries to attach to and debug T-SQl code [...]

Implement SQL IN and NOT IN operators and sub-queries using LINQ to SQL

SQL IN and NOT IN operators with a combination with sub-queries can be really useful in some cases. An example of this is below. All queries in this post don’t contain real tables.

1: select *

2: from table1 t1

3: where t1.id in (

4: [...]

Find and delete duplicated records in a table using t-SQL

If you do search in the internet how to solve the problem with duplicated records you will find different solutions. In this post I’ll describe the solution that I used for solving duplicated records problem. Let’s assume that there is a table named myTable with five columns (id, fk_id1, fk_id2, fk_id3, timestamp_col). In all of [...]

Concatenate nvarchar field and ntext field. Push LINQ to convert ntext to nvarchar.

Let’s assume that we have a table like

This table contains a field name of type nvarchar(50) and a field description of type ntext. Assume we need name and description field values concatenated in one field. Using LINQ we can write a query like that.

1: var result = (from r in [...]

Is it possible to check what is allocated space per table, used space per table, space used by indexes and unused space per table in SQL Server 2005?

In the samples in this blog I’ll use SQL Server 2005 sample database named “AdventureWorks”.
Yes, it is possible. There is a stored procedure (SP) in SQL Server that allows us to see what is the used space, unused space and used space by indexes for a specific table. The name of this SP is sp_spaceused. [...]