Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invalid object name

When doing...

select * from students

I get a "Invalid object name" error. Basically, I think I can see the problem in that the tables are prefixed with an object name rather than just dbo, lets call the schema "test".

So this means....

select * from test.students

The problem I have is that I can't change the SQL code (it's in release, long story) or change the tables. My question is, is there anything I can change in SQL server that will allow me to connect say with a specific SQL server user so I can still run my queries as...

select * from students

Omitting the object name, but still have the object name against the table? I can add another SQL user or something like that no problem.

I'm using Java over the jdbc protocol, so my connection string is something like jdbc:sqlserver://hostname:port;databaseName=db;user=myuser;password=mypassword

Thanks,

David

like image 383
david99world Avatar asked Mar 06 '26 15:03

david99world


1 Answers

You're looking for a default schema option, which doesn't exist for a given connection. That is to say that you can't say something like "until I say otherwise, unqualified tables are in the test schema". You can, however, set a default schema for a user. For your example, you'd do

alter user [myuser] with default_schema = [test]
like image 79
Ben Thul Avatar answered Mar 09 '26 03:03

Ben Thul



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!