Q:
You are the administrator of a SQL Server 2000 computer. The server contains a database named FinanceData that is used by a client/server application. Each employee has a SQL Server login that the application uses to access the server.Your company hires a new employee named Andrew. You create a SQL Server login named Andrew. You also create a database user named Andrew in the database and grant the database user full permissions in the database.Whenever Andrew runs the client/server application, he receives the following error message: "Invalid object name." Andrew also reports that he cannot access the database by using the application.You need to ensure that Andrew can use the application. Which Transact-SQL statement should you execute?
Answer & Explanation
Answer: A) EXEC sp_defaultdb 'Andrew','FinanceData'
Explanation: Error 208 produces the message 'Invalid object name' and occurs when an object that does not exist in the current database is referenced. If the object exists in another database, we must use the USE statement to explicitly switch the context to the correct database or we must qualify the object name with the database name. A third option is to use the sp_defaultdb stored procedure. This stored procedure is used to change the default database for a login. When a client connects with SQL Server, the default database defined for its login becomes the current database without an explicit USE statement. The default database can be defined when the login is added with
sp_addlogin. When executing sp_addlogin the master database is the default database if a database is not specified. In this scenario a SQL Server 2000 login and a user account has been created for Andrew and he has been given database access and the required permissions.
View Answer
Report Error
Discuss