SQL Tutorial - Procedures

Iamcoolz Aug 11, 2014

  1. Iamcoolz

    Iamcoolz Forum Administrator Staff Member XPG Administrator
    205/282

    Joined:
    Mar 30, 2012
    Messages:
    1,227
    Likes Received:
    507
    Trophy Points:
    205
    Gender:
    Male
    Location:
    XPG
    Console:
    Xbox One
    What is up all!

    Quick little tutorial before I go off and dream away.

    So, as described in my other posts, SQL is a hobby of mine! So I would like to show you how important a procedure is in SQL and how to even create your own and use it! So let's start off with a simple procedure of my own, straight from my own database.

    CREATE procedure [dbo].[ChangeName]
    (@oldname varchar(30),@newname varchar(30))
    AS DECLARE @clannumber smallint, @length int,@row int,@i int,@dwid int,@pos int,@dur int,@dur1 int,@ext int,@StackSize1 int,@strName varchar(30),@strExtName varchar(30),@Cdwid varbinary(4),@cdur varchar(2),@cstack varchar(2)
    begin tran
    UPDATE ACCOUNT_CHAR SET strCharID1 = @newname WHERE strCharID1 = @oldname
    commit tran
    GO
    So basically what we are doing here is a basic name change, and including all the variables included. This procedure is literally taking my OLDNAME and converting into a varchar(30) so max 30 characters, and then allowing me to set my own name! So I would put that procedure into my database, and use an exec query.

    CreateProcedure = Does what it says, creating a procedure named ChangeName in the default database or [dbo].

    begin tran = Begin the transaction, go through and if errors occur, stop.

    Commit tran = commit transaction, so go through with the command if no errors.

    EXEC ChangeName 'Current Character Name','New Character Name'
    So we would set my currentname (Iamcoolz) and then my new name (XPGIamcoolz) inbetween those apostrophes and boo ya! Run that query and the procedure does all the work for you.

    Any questions, I know this one is short! just feel free to ask.
     

Share This Page

Close