Results 1 to 2 of 2
  1. #1
    Join Date
    May 2003

    Unanswered: DDL create user in T-SQL stored proc/trigger

    Hello SQL Server programming gurus:

    I am trying to create a trigger that fires after a user logon and logoff and does the following:

    creates a new user
    deletes data from old temp table

    Then I need to create a stored procedure that executes dynamically to
    drop old users
    remove the old user account access

    We are running SQL Server 2000.
    Since I am new to T-SQL programming could anyone help point me in the right direction? Can I write dynamic SQL in a trigger to do these things?

  2. #2
    Join Date
    Feb 2004
    In front of the computer
    Provided Answers: 54
    I really don't think you want to try that using a trigger. It sounds like a really bad idea to me.

    First and foremost, I don't know of any way to launch a trigger on a login or logout event. You could probably approximate this using either SQL Profiler or a "watchdog" process, but the fundamental idea isn't supported by SQL Server itself, so you'll need some kind of "helper" to get the job done.

    Next, I'd be really leary of having users created "on the fly" by anyone, much less what you seem to be describing where every login has the ability to create users! I can't imagine a scenario where that idea would appeal to me, unless it was to torment some dba that was going to inherit that code after I'd left. The thought positively gives me the willies!

    The temp tables really aren't any problem... SQL Server simply drops temp tables after the user logs off. You really don't need to do any "care and feeding" of them, they are completely expendable.

    If you can explain what you are trying to do (in English, not Transact-SQL), I'd be willing to bet that someone here can offer you some ideas that will help a bunch!


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts