Code Review - Check it out and be inspired.

The Digital Tool Factory Blog

How to Truncate a Table in Sql Server

I hadn’t used this handy tool in sql server in a while and actually had to look it up recently, so here it is in the code review.

TRUNCATE TABLE “table_name”

Truncating not only deletes all of rows in the table, but it deletes all information about the table, which makes all auto numbering integer fields start over at 1.  Not complicated, but surprisingly few people know about it.

 

This post originally appeared on the Stronico blog – with the absorption of Stronico into Digital Tool Factory this post has been moved to the Digital Tool Factory blog


15
Sep 10


Written By Steve French

 

The List in C#

The first entry in my Code Review is the List<>.

So far, the List is my favorite sort of array in C#.  It has the benefits of

  • being obvious in naming
  • you do not have to know the size when it is declared – the List can expand or contract as needed
  • adding items to the array is quite simple, as is looping through the array
  • finding items in the list is easy as well

The basic List syntax is this

List<string> lstContactList = new List<string>();

At first the syntax looks a bit off, what with the odd angle brackets<> and the () at the very end of the declaration, but that is the only counter-intuitive part of the List.  Please note, a list can hold any type of object or type, not just strings.

To add to the list simply use the .Add syntax, for example

lstContactList.Add (“Bob Raindorf”);.

You can find the index of a particular list item by simply using this syntax:

lstContactList.IndexOf(“Bob Raindorf”);

Once you identify the  identified, you can replace the value of the list item quite simply by

lstContactList[lstContactList.IndexOf("Bob Raindorf")] = “Robert Raindorf”;

If you want to loop through the list, just do this

foreach (string str in lstContactList)
{
InsertToDB(str);
}

To clear the list, just do this

lstContactList.Clear();

That’s all I need to remember (for now anyway), hopefully the act of writing this pushed it into long term memory.

 

This post originally appeared on the Stronico blog – with the absorption of Stronico into Digital Tool Factory this post has been moved to the Digital Tool Factory blog


07
Sep 10


Written By Steve French

 

Introducing the new Code Review Category

WorkmodeOne of the lessons I learned from John Medina’s excellent book Brian Rules is that of elaborative rehearsal, which is (roughly) defined as remembering something more strongly by doing something with the new information, like giving a book report or relating that information back into something you already know.   Example: Say you already know the geography of Central Asia, if you wanted to remember the story of Genghis Khan, you could relate Genghis’ story to the already known geography, and then giving an oral report on old Genghis.

Like most coders, I sometimes forget code syntax of functions I don’t use that often.  I am now going to start writing up short expositions on the functions I have to look up in the hope that writing up the exposition will help transfer the function into long term memory.

photo credit: akaalias
Creative Commons License

 

This post originally appeared on the Stronico blog – with the absorption of Stronico into Digital Tool Factory this post has been moved to the Digital Tool Factory blog


07
Sep 10


Written By Steve French

 



Copyright 2011 Digital Tool Factory. All Rights Reserved. Powered by raw technical talent. And in this case, WordPress.