Luciano Evaristo Guerche
A brazilian geek interested in .NET technologies
- 
Have just joined to Friendster.com and Tribe.netI have just joined to Friendster.com and Tribe.net. Filled their forms and send email invitation to friends, but nobody has replied so far. What about being part of two network and having no pals? 
- 
My foaf.rdfI have just created my FOAF file. I do not fully understand its purpose or uses, but have tried it even so. I must read more about Semantic Web and social networking. For what I have seen so far, they seem pretty fascinating. 
- 
For those who still uses VB 6 and have to deal with unindented code...I have created this Visual Basic Addin some time ago to solve a recurring problem I used to have: Deal with big projects with unindented code anywhere. I am not sure it covers 100% VB 6 syntax because I did not find any "VB 6 reserved keywords" list on Internet that time. So try it and extend it in case any keyword is missing. 
- 
How to implement ReplaceAll in Java...Took a look at some snippets I wrote some time ago and found the code below. Hope my blog's readers enjoy it. It is not pure .Net code but can be converted to. 
- 
Robert Scoble has mentioned my name in one of his postingsToday, just find out my name has been mentioned in Google vs. Yahoo, a posting written by Robert Scoble, the Microsoft employee who currently reads 1260+ feeds a day! 
- 
The Road To IndigoI have just read an excelent posting from Benjamin Mitchell concerning Indigo techology: The Road To Indigo 
- 
How to implement a work queue in SQL serverHow to implement a work queue in SQL server script is attached just below. Any comment is welcome. 
- 
email received from Duncan MackenzieTomorrow morning, when I opened Outlook Express and checked my email inbox at hotmail.com, I could not believe I have received an email from Duncan Mackenzie, MSDN Content Strategist for Visual Basic, commenting on the email I have sent to Robert Green, a Visual Basic .Net team member. 
- 
Delimited List to TablePeter Debetta published the article "Delimited List to Table" and stated in the article "I'm sure this could be optimized in a number of ways, and could also be made to trim extra spaces as well. If you have any suggestions, please add them as comments for one and all to see.". 
- 
Stored Procedure ForeignkeysAnalyze/*Because I usually deal with databases consisting of hundreds of tables, I developed the stored procedure attached to try to make my life easier. Hope you enjoy it. Any comments about it are welcome.The stored procedure attached reads SQL server system tables and generates some valuable outputs, to name:1. List of tables, including their treeLevel (nodeLevel)treeLevel (nodeLevel): defined based on existing relationships between tablesExample: table A relates to table B one to many; table B relates to table C one to many. Based on the relationships table A is on nodeLevel 1; table B on nodeLevel 2 and table C on nodeLevel 3How to use this information:a) Suppose DBA wants to delete all tables. He/she may soon face a lot of foreign key constraint errors. How to avoid it? Delete all tables from nodeLevel n, then delete all tables from nodeLevel n - 1, etc.b) Suppose DBA wants to bcp/bulk insert all/some the tables of a database. Soon, he/she may face a lot of foreign key constraint errors. How to avoid it? bcp/bulk insert all tables from nodeLevel 1, then all tables from nodeLevel 2, etc.2. List of relationships3. List of recursive relationshipsRecursive relationships: are the ones where one child table can achieve a parent table through another table(s).Example: table A relates to table B one to many; table B relates to table C one to many. table C can achieve table A through table B, so there is an recursive relationship.4. List of doubtful relationshipsDoubtful relationships: child table may achieve (direct or recursively) a parent table through only one way. If that does not happen, there are doubtful relationships between child and parent table. When a doubtful relationship exists it is hard to keep ACID rules on the tables involved in the relationshipExample: table A relates to table B one to many; table B relates to table C one to many; table A relates to table C one to many. table C can achieve table A two ways. First, table C relating to table B, then table B relating to table A and second, table C relating to table A. How can I assure both ways I will get same record from table A? Relationships are redundant and ACID rules are hard to assure.How to use this information: Analyze the output and exclude the ones which are assured to be redundant5. List of circular referencesCircular references: When one table eventually depends on itselfExample: table A relates to table B one to many; table B relates to table C one to many; table C relates to table A one to many.How to use this information: Analyze the output and exclude the relationship(s) which is/are causing circular reference*//************************************************************************** Drops procedure if it already exists * *************************************************************************/IF EXISTS(SELECT *FROM dbo.sysobjectsWHERE id = OBJECT_ID(N'[dbo].[ForeignkeysAnalyze]') AND 1 = OBJECTPROPERTY(id, N'IsProcedure')) BEGINDROP PROCEDURE [dbo].[ForeignkeysAnalyze]ENDGO /************************************************************************** Creates procedure * *************************************************************************/SET QUOTED_IDENTIFIER OFFGO SET ANSI_NULLS OFF GO CREATE PROCEDURE [dbo].[ForeignkeysAnalyze]ASBEGIN/************************************************************************** Sets NOCOUNT ON * *************************************************************************/SET NOCOUNT ON/************************************************************************** Selects table names * *************************************************************************/SELECT dbo.sysobjects.name, 1 AS treeLevel INTO #tablesFROM dbo.sysobjectsWHERE dbo.sysobjects.type = 'U' AND dbo.sysobjects.name NOT LIKE 'dt_%' ORDER BY dbo.sysobjects.name/************************************************************************** Selects relations * *************************************************************************/SELECT sysobjectsParent.name AS parentTable, sysobjectsChild.name AS childTableINTO #relationsFROM dbo.sysforeignkeysINNER JOINdbo.sysobjects AS sysobjectsChildON dbo.sysforeignkeys.fkeyid = sysobjectsChild.idINNER JOINdbo.sysobjects AS sysobjectsParentON dbo.sysforeignkeys.rkeyid = sysobjectsParent.idGROUP BY sysobjectsParent.name,sysobjectsChild.name ORDER BY sysobjectsParent.name,sysobjectsChild.name /************************************************************************** Creates and fulfills recursive relations * *************************************************************************/DECLARE @Step AS smallint SET @Step = 1SELECT #relations.parentTable,#relations.childTable, CAST('\' + #relations.parentTable + '\' + #relations.childTable + '\' AS varchar(1024)) AS Path, #relations.childTable AS rightOfParent,#relations.parentTable AS leftOfChild,@Step AS StepINTO #relationsRecursiveFROM #tablesINNER JOIN#relations ON #tables.name = #relations.parentTableORDER BY #tables.treeLevel,#tables.name WHILE EXISTS(SELECT #relationsRecursive.parentTableFROM #relationsRecursiveINNER JOIN#relations ON #relationsRecursive.childTable = #relations.parentTableWHERE #relationsRecursive.Step = @Step AND CHARINDEX('\' + #relations.childTable + '\', #relationsRecursive.Path) = 0 ) BEGININSERT INTO #relationsRecursive(parentTable, childTable, [Path], rightOfParent, leftOfChild, Step ) SELECT #relationsRecursive.parentTable,#relations.childTable, #relationsRecursive.Path + #relations.childTable + '\',#relationsRecursive.rightOfParent, #relationsRecursive.childTable, @Step + 1 FROM #relationsRecursiveINNER JOIN#relations ON #relationsRecursive.childTable = #relations.parentTableWHERE #relationsRecursive.Step = @Step AND CHARINDEX('\' + #relations.childTable + '\', #relationsRecursive.Path) = 0 SET @Step = @Step + 1END/************************************************************************** Sets treeLevel field * *************************************************************************/WHILE EXISTS(SELECT #tablesChild.treeLevelFROM #tables AS #tablesChild INNER JOIN#relations AS #relationsChildON #tablesChild.name = #relationsChild.childTableINNER JOIN#tables AS #tablesParentON #relationsChild.parentTable = #tablesParent.nameWHERE #tablesChild.treeLevel < #tablesParent.treeLevel + 1 AND NOT EXISTS(SELECT #relationsRecursive.parentTableFROM #relationsRecursiveWHERE #relationsRecursive.childTable = #tablesParent.name AND #relationsRecursive.parentTable = #tablesChild.name ) ) BEGINUPDATE #tablesChildSET #tablesChild.treeLevel = #tablesParent.treeLevel + 1FROM #tables AS #tablesChild INNER JOIN#relations AS #relationsChildON #tablesChild.name = #relationsChild.childTableINNER JOIN#tables AS #tablesParentON #relationsChild.parentTable = #tablesParent.nameWHERE #tablesChild.treeLevel < #tablesParent.treeLevel + 1 AND NOT EXISTS(SELECT #relationsRecursive.parentTableFROM #relationsRecursiveWHERE #relationsRecursive.childTable = #tablesParent.name AND #relationsRecursive.parentTable = #tablesChild.name ) END/************************************************************************** Creates table #relationsDoubtful * *************************************************************************/SELECT #relationsRecursive.parentTable,#relationsRecursive.childTable, COUNT(#relationsRecursive.childTable) AS Occurrences INTO #relationsDoubtfulFROM #relationsRecursiveWHERE (SELECT COUNT(#relationsRecursiveSQ.Path)FROM #relationsRecursive AS #relationsRecursiveSQ WHERE #relationsRecursiveSQ.childTable = #relationsRecursive.childTable AND #relationsRecursiveSQ.parentTable = #relationsRecursive.parentTable AND#relationsRecursiveSQ.rightOfParent = #relationsRecursive.rightOfParent ) = 1 AND( SELECT COUNT(#relationsRecursiveSQ.Path)FROM #relationsRecursive AS #relationsRecursiveSQ WHERE #relationsRecursiveSQ.childTable = #relationsRecursive.childTable AND #relationsRecursiveSQ.parentTable = #relationsRecursive.parentTable AND#relationsRecursiveSQ.leftOfChild = #relationsRecursive.leftOfChild ) = 1 GROUP BY #relationsRecursive.parentTable,#relationsRecursive.childTable HAVING COUNT(#relationsRecursive.childTable) > 1ORDER BY #relationsRecursive.parentTable,#relationsRecursive.childTable /************************************************************************** Sets NOCOUNT OFF * *************************************************************************/SET NOCOUNT OFF/************************************************************************** Selects tables name (with treeLevel included) * *************************************************************************/SELECT '#tables' AS Source, #tables.name, #tables.treeLevel FROM #tablesORDER BY #tables.treeLevel,#tables.name /************************************************************************** Selects relations * *************************************************************************/SELECT '#relations' AS Source, #relations.* FROM #relationsORDER BY parentTable,childTable /************************************************************************** Selects recursive relations * *************************************************************************/SELECT '#relationsRecursive' AS Source, #relationsRecursive.* FROM #relationsRecursiveORDER BY parentTable,Path /************************************************************************** Selects doubtful relations * *************************************************************************/SELECT '#relationsDoubtful' AS Source, #relationsDoubtful.parentTable, #relationsDoubtful.childTable, #relationsRecursive.Path FROM #relationsDoubtfulINNER JOIN#relationsRecursive ON #relationsDoubtful.childTable = #relationsRecursive.childTable AND #relationsDoubtful.parentTable = #relationsRecursive.parentTable ORDER BY #relationsDoubtful.childTable,#relationsRecursive.parentTable, #relationsRecursive.Path /************************************************************************** Selects circular relations * *************************************************************************/SELECT '#relationsCircular' AS Source, #relationsRecursive.parentTable, #relationsRecursive.childTable, #relationsRecursive.Path FROM #relationsRecursiveWHERE EXISTS(SELECT #relationsRecursiveSQ.parentTableFROM #relationsRecursive AS #relationsRecursiveSQ WHERE #relationsRecursiveSQ.parentTable = #relationsRecursive.childTable AND #relationsRecursiveSQ.childTable = #relationsRecursive.ParentTable ) ORDER BY #relationsRecursive.childTable,#relationsRecursive.parentTable, #relationsRecursive.Path /************************************************************************** Finishes procedure * *************************************************************************/RETURNENDGO SET QUOTED_IDENTIFIER OFFGO SET ANSI_NULLS ON GO EXECUTE [dbo].[ForeignkeysAnalyze]GO /*  dbo.ForeignkeysAnalyze.storedprocedure.sql dbo.ForeignkeysAnalyze.storedprocedure.sql*/