Tuesday, April 8, 2014

Find Stored Procedure By Name

To find a stored procedure by name, use one of these queries:

select * from   sys.procedures
where    name like '%name_of_proc%'
or
select text 
from 
    syscomments c
    inner join sys.procedures p on p.object_id = c.object_id
where 
    p.name like '%name_of_proc%'
or
select * 
from
    information_schema.routines
where
    routine_name like '%name_of_proc%'

Monday, March 31, 2014

Code Analysis with NDepend

 

When our projects reach a certain size it is very hard to determine the complexity of our code. It gets harder and harder to see the overall picture. It also becomes very easy to introduce unnecessary complexity to parts of our system that we don’t want to. In simple words, it’s easy to get lost. Especially if there are may people working on the project.

 

On top of many other tools, practices and principles like unit tests, integration tests, acceptance tests, continuous integration, it is static code analysis tools like NDepend that come into play.

 

Monday, September 9, 2013

The Story Of The Modern Day Developer

The Story Of The Modern Day Deve
Software Developer, a "Programmer" even an "Engineer" or a "Craftsman", although there are substantial differences between these according to some people, when we say any of them we mean one thing....an organism that transforms coffee into code :) so I will continue with the term "Developer" and I wouldn't like to go into that discussion right now because it can turn out to become a book.

We have come a long way from being the "basement" nerds, that nobody wants to talk to, to the modern day mixed media served image of super-rich-enterpreneur-programmer(which is sadly just a few lucky ones). So where is the truth? What are we, where are we? How do we manage to form a picture of ourselves and waht we want to accomplish in todays diversity of technologies and approaches to software development?

I know it maybe not much. But, having been there for quite a while both as amateur since I was a little kid typing random programs in Basic on my Commodore 64 back in the 90's, then professionally since 2005, all the way until today. I will try to share my view and experiences of what I consider the most important values of a modern day developer by answering dozen of questions.

Friday, August 9, 2013

Sql Server: datetime vs datetime2 recap

The MSDN documentation for datetime recommends using datetime2.

datetime2 has larger date range, a larger default fractional precision, and optional user-specified precision. Also depending on the user-specified precision it may use less storage.

Furthermore, datetime2 has a date range of "0001 / 01 / 01" through "9999 / 12 / 31" while the datetime type only supports year 1753-9999.

Also, if you need to, datetime2 can be more precise in terms of time; datetime  s limited to 3 1/3 milliseconds, while datetime2 can be accurate down to 100ns.
Both types map to System.DateTime in .NET - no difference there.

Friday, July 19, 2013

Get all stored procedures related to a table

To get all stored procedures related to a table:

Option 1:
 SELECT DISTINCT so.name  
 FROM syscomments sc  
 INNER JOIN sysobjects so ON sc.id=so.id  
 WHERE sc.TEXT LIKE '%tablename%'  
Option2:
 SELECT DISTINCT o.name, o.xtype  
 FROM syscomments c  
 INNER JOIN sysobjects o ON c.id=o.id  
 WHERE c.TEXT LIKE '%tablename%'  

Tuesday, July 16, 2013

Run a single test method with maven

To run a single test method in Maven, you need to provide the command as: 

mvn -Dtest=TestClass#testMethod test

where TestClass is the test class name and testMethod is the test method, wild card characters also work (both in the method name and class name).

Thursday, July 4, 2013

Sql Server: Delete duplicate rows with CTE

Here's a code snippet to remove duplicate rows in a table:

 WITH CTE (Column1, Column2, DuplicateCount)  
 AS  
 (  
 SELECT Column1,Column2,  
 ROW_NUMBER() OVER(PARTITION BY Column1,Column2 ORDER BY Column1) AS DuplicateCount  
 FROM TheTable  
 )  
 DELETE  
 FROM CTE  
 WHERE DuplicateCount > 1  
 GO  


More on Common Table Expressions(CTE) can be found here:

http://msdn.microsoft.com/en-us/library/ms190766(v=sql.105).aspx

C#, Linq: Filtering duplicates out of an IEnumerable

Problem: Filtering out(removing duplicates) from an IEnumerable

One possible solution with using linq would be to group by key and take the first element of each group

enumerable.GroupBy(x => x.key).Select(g => g.First())


Sql Server: Get all tables containing column with a specified name

Here's a useful query:

SELECT c.name AS ColName, t.name AS TableName
FROM sys.columns c
    JOIN sys.tables t ON c.object_id = t.object_id
WHERE c.name LIKE '%ColumnName%'
 It will do a join on sys.columns and sys.tables to get all tables that contains the specified column in sql server.

Thursday, April 11, 2013

Test Driven Development


It is pretty hard writing an article on something that so many super cool authors have written books about. But, as I said it is my own experience learning and embracing TDD that I want to share here so that maybe I can help someone out there that can relate to this. And also I can always remind myself of the process I went through while learning it.
Bottom line is that nobody can teach you a programming approach like this by writing or making videos about it. They can only get you started and they can tell you why you should do it. The real power comes by you actually digging into it. The more you do it the more you master it and the more you can actually feel the benefits of it. I didn’t believe when people said it was addictive, in matter of fact I opposed to the whole idea. I was one of the people that thought this is a waste of time and that you can achieve more by just writing production code….and boy….was I wrong about it.
We have to start somewhere, so why not at the very core of it. The unit test definition.