Posts Tagged ‘T-SQL’

Deleting sequential duplicates with TSQL

I was recently given a du-duping task which was much more difficult than I anticipated and taxed my SQL brain to its limits. I thought of using a CTE to do this but all of the examples I could find for deleting records with a CTE wouldn’t have worked in my situation. Essentially the table […]

Unsigned Integer Arithmetic in SQL

Not the sexiest blog title in the world but I thought I’d knock up a little post on the behaviour of MySQL and SQL Server with integer subtraction. How would you expect a database system to behave with positive and negative data types? Microsoft SQL Server doesn’t really have unsigned data types. All integer types […]

Breaking my Non-Equi Join cherry

There’s few SQL techniques you seem to keep in the cupboard gathering dust. I don’t think I’ve ever needed to use RIGHT JOIN outside of the classroom. I can recall using FULL OUTER JOIN, just once, to show an employer how not-in-sync their "integrated system" was. Today I broke my professional Non-Equi JOIN cherry! I […]

Views or functions cannot reference themselves directly or indirectly

Today I received the following SQL Server error which I had never encountered before. Msg 4429, Level 16, State 1, Line 1 View or function ‘Table_1’ contains a self-reference. Views or functions cannot reference themselves directly or indirectly. Msg 4413, Level 16, State 1, Line 1 Could not use view or function ‘Test.Table_1’ because of […]

Get database size With T-SQL and MySQL

I’ve recently been busy documentation various systems at work and came up with these queries to get a list of databases and their sizes for each SQL Server. These queries will show the server name, database names, and their sizes in KB, MB and GB. For SQL Server 2005 & 2008 — SQL Server 2005 […]