This is a concoction of geeky posts, programming posts and just general stuff that is in my brain.

It might be updated often but then again it might not...

 

 

SQL Server - Locating objects in your Stored Procedures

Recently, I have been doing lots of SQL Server stuff so decided to add a few bits and pieces on here. 

First up, finding objects within your stored procedures. In this case, specifically views and tables.

This query is useful to find out if you have tables or views that aren't in any stored procedures. It gives you the object name, type of object and the number of stored procedures it appears in.

 

 

;with q as
(
Select   t.Name as [ObjectName],
       t.type_desc as [ObjectType],
      p.Name as [ProcedureName]
        
From sys.tables t
Left Join sys.procedures p on object_definition(p.object_Id) Like '%' + Replace(t.name, '_','!_')  + '%' ESCAPE '!'

    Union
Select  v.Name,
       v.type_desc,
      p.Name
   
From sys.views v
Left Join sys.procedures p on object_definition(p.object_Id) Like '%' + Replace(v.name, '_','!_')  + '%' ESCAPE '!'

)
Select    ObjectName,
       ObjectType,
       Count(ProcedureName) as [NumberOfOccurrences]
From q
Group by ObjectName, ObjectType

To list the names of the procedures that the object appears in you would change it to the following:

;with q as
(
Select   t.Name as [ObjectName],
       t.type_desc as [ObjectType],
      p.Name as [ProcedureName]
         
From sys.tables t
Left Join sys.procedures p on object_definition(p.object_Id) Like '%' + Replace(t.name, '_','!_')  + '%' ESCAPE '!'

    Union

Select  v.Name,
       v.type_desc,
      p.Name

From sys.views v
Left Join sys.procedures p on object_definition(p.object_Id) Like '%' + Replace(v.name, '_','!_')  + '%' ESCAPE '!'

)
Select    ObjectName,
       ObjectType,
       ProcedureName
From q
Where ObjectName = 'YOUR_OBJECT_NAME'

 

 

Posted by codingbadger at 09:26
Tags :

Pushing a local Git repository to a new remote repository

For reasons completely unknown I find it *really* difficult to remember the syntax in Git to push a new local repository to a remote destination.

So to stop from scratching my head about it, I am going to put it here. Two reasons:

1. so I know I can find it

2. it might help someone else looking for it

So, you've create a local git repository on your machine and what to push it to a remote server? (In this example I am going to use http://BitBucket.org)

Firstly, log in to BitBucket and create a new blank repository.

Once that is done, using git bash in your local repository execute the command

git remote add origin git@bitbucket.org:{BITBUCKET_USERNAME}/{REPO_NAME}.git

Obviously, replacing {BITBUCKET_USERNAME} & {REPO_NAME} with the real values!

This will add the the BitBucket URL as a local remote alias called "origin" to your local repo.

Now you need simply need to push your local repository (usually called master) to your remote repository. Which is called origin as we have just given it that alias!

To be clear, you can call your remote alias anything you like it doesn't have to be origin. In this instance calling your alias bitbucket would make sense.

git push origin master

And that is all you need to do! Really simple but for some reason I can never remember it.

As a side note, there is also a really handy git reference guide on GitHub

Posted by codingbadger at 13:28

Web Applications - You are looking in the wrong place

Bit of a cryptic title I know, but let me explain.

There have been a number of occasions on Twitter when a tweet has wandered in to my timeline along the lines of:

"What's the keyboard shortcut in GMail to send a message to Archive? #lazyweb"

Ok so that question may be a bit too simple but it is generally "How can I get [Web App] to do [some specific task]" If I don't know the answer then a quick search normally brings up the answer.

But I'm not immediately switching to Google for my searching, oh no boys and girls... I'm searching here first:

Web Apps

Now just to get one small and tiny detail out of the way, I am a Moderator on this site, so it's natural that I am going to say how brilliant it is! But here is the thing, it really is brilliant!

That Trello thing everyone is talking about? Well a question was asked about Trello on Web Applications waaay back in September 2011. And there are plenty more really awesome questions lurking about.

I would bet that if you have a query about anything Trello related, it has probably already been asked.  If by some miracle it hasn't, then you should ask it. The Trello Developers actively use Web Applications and answer any queries you may have. Pretty cool huh?

Moving on to Google. I don't know a single person who doesn't use Google in one form or other.  Web Applications is an Aladdin's cave full of nifty little Google tricks and tips.

Did you know that Google adds a load of JavaScript nonsense to your search results? Want to get rid of it? Well, here is the answer.

Have you ever wondered what the query string parameter `shva` means when logging in to GMail? Well, wonder no more!

Are you trying to work out how to automatically post your Google+ posts to your Facebook? Well, conserve your brain power and check out this answer.

Another nice Web Application that is getting a lot of attention at the moment is, If This Then That. This super simple Web App is all about Triggers, Actions & Channels. If this happens then do that. This could be you posting on Google+, the that could be your post automagically making it's way to your Facebook. 

This is a simple example but there are lots of Channels available (The Google+ and Facebook in this example) such as Email, SMS, Calendar and many more. Want to get an email if the weather forecast for tomorrow is raining? IFTTT can do that.

In short, Web Applications is an awesome place to ask questions about erm... Web Applications! 

But wait, there are some things that you should know. Web Applications is not the place to ask for alternatives or Web App requests. Questions like this:

Is there a Web App that will do [x] for me?

This is a bad question!

So what can you do? Well, you do some research yourself! Yes, the community is here to help you but they're not here to just spoon feed you. The same principle applies across the Stack Exchange network, we aren't just being nasty :)

A better question would be:

I am looking for a Web App that will do [x] for me.

I have done some research and the following Web Apps are almost suitable:

  • Web App A
  • Web App B
  • Web App C

But here are the sticking points:

  • Web App A doesn't do E
  • Web App B doesn't F
  • Web App C doesn't do E & G

Can anyone recommend a solution to these problems? I would really like to use Web App A but the fact that it doesn't do E is really putting me off

Yes, you have had to put some effort in but this is a much better question and will more than likely get some awesome answers!

If you aren't sure you can always test the water in Chat or even post a question on the Web Apps Meta site.

By browsing through the questions on Web Applications you will find so many useful apps & services out there that you probably didn't know existed! You might even know how to answer a few questions to!

So next time you have a question about a Web Application, instead of immediately searching through no end of useless websites via Google, give Web Applications a try and see if we can help you.

 

P.S The answer is typing `e` when in the message ;-)

Posted by codingbadger at 20:44

Stack Overflow Careers - not just for the Stack Overflow hardcore

Pretty much every developer in the world knows about Stack Overflow, searching for a solution to a development problem in Google will almost certainly throw up a pretty damn good answer on Stack Overflow.

Along will many other Q&A sites that are now available on Stack Exchange there is a Careers site too.

Careers 2.0 is a place to show off your awesomeness. And I don't mean your awesomeness on Stack Overflow - I mean everywhere! 

As Careers 2.0 is tied to Stack Overflow there are certain aspects of it which are designed to promote your activity on Stack Overflow.

Such as the tags you are active in:

Tags

Your Stack Exchange accounts:

SE Accounts

Along with any "top answers" you feel that are exceptionally good you need to show them off.

And that is it - the rest of your profile is up to you.

 

I will go through and show you some of the main sections that are on your Careers 2.0 Profile to demonstrate that most of this is nothing to do with Stack Overflow.

A personal statement

personal_statement

Add whatever you like here - it's entirely up to you. Just make it good!


Tech

Add the technologies you are interested in and if you want, the technologies you aren't interested in.

A number of the sections that relate to technology allow you to choose the same tags that Stack Overflow uses when you post a question. I am guessing this makes it easier for Employers to search through candidates who like a particular technology.

Experience & Education

Fairly self explantory to be honest. You add your previous roles along with a short description, time frames and the technology you used.

OpenSource

This is where it can get interesting. You are able to to add links to any open source projects that you have worked on. This allows you to put your real projects out there on display and make it easy for potential Employers to find and immediately see how you would normally write code. Remember, this is code that you have written properly, not some pseudo crap that you have quickly knocked together so you can earn a quick 20 or 30 rep on Stack Overflow.

Apps

Again more opportunities for you to show off your real acheivements.

Writing & Reading

The Writing section allows you to link to Amazon for any books that you may have written and also to any articles or blog posts you may have written that you feel will make you stand out from everybody else.

The Reading section is pretty similar and lets you link to Amazon for any books you have read and again any blog posts that you have read.

Obviously, you should pick and choose the relevant books that you have read. I'm pretty sure potential Employers do not need to know that you have read the "Shoot Annual" from 1983 :)

 

There are other sections that you can complete on your profile along with some other nice pieces of functionality but I don't want to spoil all of the surprises!

I get the impression that a lot of people think that Careers 2.0 is very closely tied to Stack Overflow and more specifically to the reputation that you have on Stack Overflow. This is simply not the case and I hope you can now see why your reputation on Stack Overflow is a pretty small factor when it comes to your Careers 2.0 profile.

It seems I am in good company as Joel Spolsky blogged about why reputation on Stack Overflow isn't what Careers 2.0 is about.

Oh, and here is a link to my Careers profile should you wish to have a look :)

Posted by codingbadger at 09:36

Scripting out the Schema & Data in SQL Server 2008

SQL Server 2008 has a neat feature that allows you to script out an object. Not really ground breaking so far. However, where this differs from SQL 2005 is that you can script out:

  • the schema
  • the data
  • the schema & data

You would think this option is available to you by right clicking directly on the object (typically a table for scripting out data and schema) but it isn't - you have to start on the database.

Right click on your database and select Tasks >Generate Scripts...

Step _One _Generate _Scripts

This will fire up a wizard to generate the scripts for you. 

Click Next and you will be prompted to select the objects you want to script out. I am going to choose one table for this purpose as it's easier.

Step _Two _Select _Object

Click Next

This is the important part, by default SSMS defaults to Schema Only to amend this to include the data you need to click Advanced

Step _Three _Click Advanced

Now scroll down to the proprty named Types of data to script and select an option from the drop down.

Step _four _type _of _data

Click OK and follow the rest of the wizard.

And there you have it, a simple way to script out your schema and data via SSMS 2008.

 

Note: If you are on SQL Server 2005 then I would recommend using an add-on such as SSMS Tools Pack as it includes this type of functionality which isn't available pre SQL 2008.

Posted by codingbadger at 13:05

Authors

Recent Comments

Powered by Disqus