简体   繁体   中英

How to NOT use fully qualified table names in MS SQL Server 2008 R2

I've been asked to make some changes in an old asp-classic application. The production server and the server they use for testing and dev or over 20 routers away and the lag time between my typing and then seeing the type is horrible. So I set up a server here, just like theirs (MS Server 2008) installed MS SQL Server 2008 R2. I thought I configured my database just like theirs. They have 100s of thousands of lines of old vbscript.

I backed up the test database on the remote side, copied it over to my server and restored it there. I copied the body of script they have over. Site is up and running. But.... Anything that requires a query to the database creates the error "Invalid object name 'atable'. Looking at their code and there isn't a fully qualified name anywhere. I log on to the remote server start up Management Studio and sure enough you dont need fully qualified names to make any queries. I asked them if I could change all the code to use fully qualified names and the answer was no. I asked how they had configured the database, and the answer was a former contractor set it up that way. (and they like it)

So my questions; is there a configuration option in MS SQL Server 2008 to default to not using fully qualified names? How could they get around not using database, owner, schema in their code? I login as the application user and that doesnt seem to help as well.

Please, I know we should use fully qualified names as best practices. I've read the comments concerning performance gains/losses. Their database instance uses a schema name when you automatically script out a create database script. If I use that schema name to preface table names all is good. They just dont want me doing that in any script I edit or create for them.

The order of resolution of an object that is not specified (select * from table1) is sys then the user's default schema then finally dbo. So SQL Server (given the database context) will look for table1 in the sys schema, then the assigned schema (which may or may not be dbo) and finally dbo. As long as everything is in dbo (which is very bad practice but you are stuck with that) everything will be found. Its like using one room to store everything.

I have worked for a very astute manager, who supports many databases, who makes it a practice to identify all his objects as three part names -databasename.schema.object but I understand that Microsoft intends to stop supporting this type of name resolution in the future. But at the very least its extremely common to see schema_name.object_name for all objects in scripts.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM