SQL Server: Can the same table exist in multiple schemas

They are 2 different objects, check the object_id


You are correct.

CREATE TABLE foo.T
(
c int
)

and

CREATE TABLE bar.T
(
c int
)

creates 2 separate objects. You could create a synonym bar.T that aliases foo.T though.

CREATE SCHEMA foo
GO
CREATE SCHEMA bar
GO
CREATE TABLE foo.T(c INT)
GO
CREATE SYNONYM bar.T FOR foo.T;
INSERT INTO foo.T VALUES (1);
SELECT * FROM bar.T;

Yes, it can. Just try it

CREATE SCHEMA OneSchema AUTHORIZATION dbo;
CREATE SCHEMA TwoSchema AUTHORIZATION dbo;
CREATE TABLE dbo.SomeTable (foo int);
CREATE TABLE OneSchema.SomeTable (foo int);
CREATE TABLE TwoSchema.SomeTable (foo int);

A schema is both a securable and part of the "namespace"

Tags:

Sql Server