Determine What User Created Objects in SQL Server
To quickly identify who created SQL Server objects, join the sys.objects
view, sys.schemas
, and sys.database_principals
. The principal_id
column connects object owners to schemas. Review this SQL snippet:
The above statement retrieves object name, creator, and created timestamp. Alter the WHERE
clause to target your specific objects.
Deep Dive: Navigating the Object Creation Mystery
Schema Changes History report in SQL Server Management Studio presents a clear picture of all DDL statements, which aids in identifying the time and user associated with object creation, alteration, or deletion.
For scenarios where the principal_id
might return NULL, this report reflects the login name tied to the DDL statement execution. Keep in mind, in case of shared logins, this might not accurately point at an individual.
For a thorough audit, especially when precision is key, exploring SQL Server traces or Extended Events could be beneficial. Apart from continuous monitoring, this feature records a detailed history of actions, mapping them back to the responsible login.
But remember, if users have dbo
rights or are closely tied to the schema owner, principal_id
may not accurately reflect the original creator.
Taking a Methodical Approach: Tips for Historical Unearthing
For times when principal_id information is missing, or when dealing with an older SQL Server 2005 version, a workaround might be to explore the sysobjects
table, joined with sysusers
:
While this strategy can unravel chronological object creation, complete recoverability can't be promised. Metadata precision tends to "blur" with system upgrades and migrations.
Third-party tools like Adam Machanic's sp_whoisactive
offer dynamic real-time insights into object changes - but remember, it doesn't retain a history.
Change Data Capture and SQL Server Audit, available in newer versions, offer a more granular trail of user activities, crucial for databases adhering to strict compliance and audits.
Was this article helpful?