Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create table in SYS schema in SQL Server?

Can one create table in sys schema SQL Server 2008 ? I know it is possible to mark table as system, but not change the schema. Any hacks for it ?

like image 946
user1309871 Avatar asked Jan 13 '23 04:01

user1309871


1 Answers

You cannot add your own objects to the sys schema.

User-defined objects cannot be created in the sys schema.
Gail Erickson [MS]
SQL Server Documentation Team
This posting is provided "AS IS" with no warranties, and confers no rights

  • Source: How can I add an object to the sys schema in SQL Server 2005?

If that's not convincing enough, consider that system objects are stored in the resource database, which is read-only:

The Resource database is a read-only database that contains all the system objects that are included with SQL Server. SQL Server system objects, such as sys.objects, are physically persisted in the Resource database, but they logically appear in the sys schema of every database. The Resource database does not contain user data or user metadata.

  • Source: msdn - Resource Database

If there does exist some undocumented method to do this, as others have stated, it's probably not in your best interest (or that of your software and team) to do so. I would suggest stepping back and attacking your problem from another angle. Perhaps some sort of mock setup?

like image 83
Tim Lehner Avatar answered Jan 22 '23 14:01

Tim Lehner