How To List All Columns In All User Tables In A Sql Server Database



TODO:

Have you ever wanted to list all columns in all User tables that exist in a SQL Server Database?

 

SOLUTION:

SELECT so.name "table", sc.name "column", sm.text "Default" 
FROM dbo.sysobjects so INNER JOIN dbo.syscolumns sc ON so.id = sc.id 
LEFT JOIN dbo.syscomments sm ON sc.cdefault = sm.id  
WHERE so.xtype = 'U'  
ORDER BY so.[name], sc.colid

 

NOTES:

There are no notes on this topic

How To Sort List Of Objects In .Net



TODO:

You have a list of objects (List<T>), let's just say List<Dog> for this example.  You want to sort them by a property called "Breed".  This example will show you just how to do that.

 

SOLUTION:

List myDogList = myDogList.OrderBy(d => d.Breed).ToList();
//or
List myDogList = myDogList.OrderByDescending(d => d.Breed).ToList();

 

NOTES:

Your list of dogs will now be sorted by Breed. 

*****Note that the default sort order is ascending.

How To Merge / Join Two Typed Lists



TODO:

Have you ever wanted to combine 2 typed lists in C#?

 

SOLUTION:

 

string data = "test,test2,test3";
string data2 = "test4;test5;test6";

List<string> list1 = data.Split(',').ToList<string>();
List<string> list2 = data2.Split(';').ToList<string>();
list1 = list1.Union(list2).ToList();

 

 

NOTES:

The example above is one that I use when I want to allow a comma or semi-colon delimited list.  For instance in my config file, people sometimes use a comma to seperate email addresses, and other times they use a semi-colon.  This will split the data one both, and join the 2 lists.