SQL Server: Can the same table exist in multiple schemas

前端 未结 5 1657
Happy的楠姐
Happy的楠姐 2021-02-20 05:26

I thought that the schemas are namespace instances and hence the same table created under 2 different schemas are 2 different objects from the perspective of the database. One o

5条回答
  •  野性不改
    2021-02-20 05:55

    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;
    

提交回复
热议问题