SQL server schema and default schema

前端 未结 3 1298
刺人心
刺人心 2020-11-30 10:53

I have a schema define in my database. Except now everytime I do a sql statement I have to provide the schema ... SELECT * FROM [myschema].table

I set

3条回答
  •  甜味超标
    2020-11-30 11:41

    Couple of options:

    1. Is your user listed under Security > Users (in SSMS)? Check the Properties (right click the name), and see if the Default schema is set in the context of the database, rather than the instance (which is what ALTER USER is setting).
    2. Create a synonym for the table you want to reference:

      CREATE SYNONYM table_name  
         FOR [your_db].[your_schema].table_name
      

      ...which will affect everyone who doesn't use at least two name notation, in the context of that database. Read more about it here. But it is associated ultimately to a schema.

    3. Check that the database selected in the "Available Databases" drop down (upper left, to the left of the Execute button) is correct.

    4. Use three name notation when specifying table (and view) references:

      SELECT * 
        FROM [your_db].[your_schema].table_name
      

提交回复
热议问题