Archive for the ‘SQL’ Category

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. [...]

Configure linked servers for Excel and MS SQL Server in MS SQL Server 2005

Linked servers allows
A linked server configuration allows Microsoft® SQL Server™ to execute commands against OLE DB data sources on different servers
Quote from MSDN

This way we have an abstract layer to other data sources (different from MS SQL Server) and we can connect them using T-SQL of MS SQL Server and only one instance of it. [...]