Assign a SQL Server Login to an Existing Db User

I was very concern about what the first post would be on my shiny new blog, actually second post because the first one was kind of a preamble and self justification, but that doesn’t really count as a post… but any who… I was under the impression that this post had to be something really profound and meaningful… until I realized that probably nobody else is going to read it but me xD. So that took off a lot of pressure and I started to think about what was the most common piece of code that I always find myself looking over and over again because I just couldn’t remember it.
Undoubtedly it was the assign login to user thing. This very simple line of code keeps slipping my mind every time I need it. The first time I encountered this problem I came across this great post that had a solution right away, but the post is quite long and has a couple of different ways to use the command but I always need just this one, so I would store the link in delicious with a little comment on the title like: (remember to use 3rd option). Not very stylish but it did the job, up until now. Maybe later I’ll post a more detail guide about the error.
So here we go, the following command will solve all your problems. Both the login and user must already exist in the server and database respectively.

USE [YourDB]
EXEC sp_change_users_login 'update_one', '[user]', '[login]'
The most common scenario where I find myself needing this is when migrating a very large database update from a development server to a quality server, where the easiest way of synch all the modifications is to manually detach/attach the .mdb file to the quality server, where the logins are already created but the association breaks with the migration.

My First Post, of my Reasons and Merits for this Blog

I’m a complete newbie to this whole blogging experience, I’m hoping this would help me exercise my communication skills and also function as a personal library for storing every piece of knowledge that you produce every day through research, analysis, development, or just plain and simple head-banging against the keyword for hours while solving an impossible problem xD.

Basically what happens to me all the time is that after solving a problem I’d try to store the solution with a brief description on my pc in an easy to find location, and a reasonable place where I would start looking in case I forgot (which I always did).  But after finding it, the instructions for the solution were not very clear, and even if I did understand them it would be useless to anyone else.  The same happened for commonly used blocks of code, and also when storing results of research on a certain topic, I’d store relevant links in delicious, which is really good, but what I really needed was to write down my own ideas and have a way of easily searching through them afterwards.

So despite this really inefficient way of working the thing that made me realize I needed to make a change was a co-worker one day in a middle of a conversation said to me: You need to open a blog! and exposed all of these reasons the I know were true but never really did anything about it, it was the little push that needed to happened to get me started. So I’ll take a moment here to give her proper merits… so Yubisay thank you!!

I hope this can be of any help to anyone else who is seriously considering opening a blog but are having second thoughts for whatever reason, my advice is “Go for it!… what’s the worse that could happen”.

Don’t mind the following code snippet, I was just trying out this syntax highlighting plug-in.  Totally recommended although I need to upgrade to the newer version.

function test(){ 
   alert("hello world!!"); 
}