I read somewhere that if we create a table in master db by using sp_sometablename it will be accessible from any other user database.
e.g.
use master
create table sp_TestTbl(Id int identity, Name varchar(20))
//Table created
Now if I execute the below
use test
select * from sp_TestTbl
it worked.
Whereas, if I don’t prefix the table name with sp_, though the table will be created in master db, but we cannot access it from any of the user database
use master
create table abc_TestTbl(Id int identity, Name varchar(20))
use test
select * from abc_TestTbl
Error:
Msg 208, Level 16, State 1, Line 6 Invalid object name
‘abc_TestTbl’.
what is the cause?
Thanks
Try this:
You need to fully qualify the table name when using from another DB
BUT
This is a completely bad idea – to create user objects in master database.
The sp_ prefix is handled differently by Sql Server – it looks for the object in master DB first for this prefix