Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server - Same table in multiple schemas

I am creating a smaller sized database in Microsoft SQL Server 2012 to keep run data from machines. The company has production machines and R & D machines. I would like to use the same table for production and R&D with a Type field specifying what the run was for simplicity. I have two schemas (prod and r_d). The permissions for the production and r_d schemas will be different. Is it possible to create a table that belongs to more than one schema? I know you can have the same table name in multiple schemas, but this creates separate objects. I would like to have the one table object to belong to multiple schemas.

Example: CREATE TABLE db_name.prod.r_d.table_name

like image 861
user3711685 Avatar asked Nov 01 '25 15:11

user3711685


2 Answers

Consider creating a synonym in one the of schemas, referencing the other schema table:

CREATE SYNONYM r_d.table_name FOR prod.table_name;
like image 50
Dan Guzman Avatar answered Nov 04 '25 07:11

Dan Guzman


No, but you can create a view in each schema on to a single table that filters the rows

like image 27
podiluska Avatar answered Nov 04 '25 08:11

podiluska



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!