Changing Table Ownership in SQL Server

April 28, 2009 by AcidRaZor · Leave a Comment
Filed under: Hosting, Programming 101, SQL Server 

Recently I had the unfortunate event of a live server being setup and used by only 1 user which wasn’t dbo. Either the programmer didn’t know any better or… well… he was the village idiot… anyway, so… on with the code. Here is a simple T-SQL statement that will get and loop through all Stored Procedures, Tables and Views and update them to use dbo (or any other user you’d like):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
DECLARE @tbl sysname
DECLARE tblcur INSENSITIVE CURSOR FOR
	SELECT name FROM sysobjects
	WHERE xtype IN ('U','V','P') AND uid = user_id('olddbuser')
OPEN tblcur
WHILE 1 = 1
	BEGIN
		FETCH tblcur INTO @tbl
			IF @@fetch_status <0
				BREAK
 
			SET @tbl = 'olddbuser.' + @tbl 
			EXEC sp_changeobjectowner @tbl, 'dbo'
	END
DEALLOCATE tblcur

Looping through a 2-dimensional array with jQuery

April 21, 2009 by AcidRaZor · Leave a Comment
Filed under: JavaScript, Programming 101, jQuery 

I recently opened my eyes to the wonderful world of jQuery. *drifts off into a fantasy*

Here’s an example of how to loop through a 2-dimensional array using jQuery. Fun & Easy:

1
2
3
4
5
6
7
var currencyTocountryName = [['USD','U.S. Dollar (USD)','$'],['GBP','British Pound (GBP)','&#163;'],['EUR','Euro (EUR)','&#8364;'],['AUD','Australian Dollar (AUD)','$'],['CAD','Canadian Dollar (CAD)','$'],['NZD','New Zealand Dollar (NZD)','$']]
$.each( currencyTocountryName,
           function( i, value ){
                   alert(value[0]);
                   alert(value[1]);
            }
);

As you can see it’s pretty straight forward. No need to have “i” be the place holder, a simple value[0] will get you the first value in the array. This must be the easiest implementation of a loop and array I’ve done in years. Sure, by now I can do a simple JavaScript loop in my sleep. But without thinking and a lot less code, jQuery allows me to leverage off that power. *Drifts off into a fantasy once again*

SEO Powered by Platinum SEO from Techblissonline