Development – Leet 4 Life

Software Development Code Samples and More

Skip to: Content | Sidebar | Footer

Tag: Query

Find all Tables With Schema that Contain a Column by Name

29 October, 2012 | SQL Server, T-SQL | By: Michael Merrell

Sometimes you need to find tables that contain a specific column name. Maybe you want to find all the tables that have a User_ID column. This was my case when I came across writing this statement although it can be used for any cases where you need to find tables that contain a specific column. It ends up being a very simple query to the sys.objects and sys.columns tables using a join. First you query from the sysobjects table and find all objects that are type ‘U’ which stands for User Table. Then you join to the syscolumns and find [Read More…]

Randomizing Results of a Data Query in T-SQL and the Entity Framework

9 April, 2012 | C#. NET, Entity Framework, T-SQL | By: Michael Merrell

There are many scenarios where you may need to randomize the results of a query that is pulling data out of your database.  When you are able to do this using straight T-SQL the statement is simple and easy.  All you have to do to get random ordered results using T-SQL is add the following order by clause to the end of your statement. The issue comes into play when you need to do this inside of the Entity Framework when pulling form LINQ to SQL. While there are several different ways you can do this when you are using LINQ to [Read More…]