How to drop database table created by specific user

Satale, Sandip (Pune) 21 Reputation points
2022-05-19T08:57:08.373+00:00

There is need to setup a maintenance job to drop database tables created by particular user list in SQL SERVER.

I was trying to use Sys.Objects, Sys.tables and sysusers objects but not able to build exact TSQL For this.

Please provide solution.

Developer technologies Transact-SQL
SQL Server Other
0 comments No comments
{count} votes

Accepted answer
  1. Olaf Helper 47,436 Reputation points
    2022-05-19T09:17:12.18+00:00

    created by particular user list in SQL SERVER.

    SQL Server don't log how created which object in a database.
    To achieve this you have to log it on your own, e.g. using a DDL trigger.
    See
    https://learn.microsoft.com/en-us/sql/relational-databases/triggers/ddl-triggers?view=sql-server-ver15

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Nandan Hegde 36,146 Reputation points MVP Volunteer Moderator
    2022-05-19T09:05:14.923+00:00

    Hey,
    Below query would help you get that list :
    select
    so.name, su.name, so.crdate
    from
    sysobjects so
    join
    sysusers su on so.uid = su.uid

    and then you can use dynamic sql to drop those


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.