Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 database name

Author  Topic 

sharankruthi
Starting Member

22 Posts

Posted - 2009-07-16 : 01:24:28
select name
from railway.mdb
where name like '#temp%'

Msg 208, Level 16, State 1, Line 1
Invalid object name 'railway.mdb'.

How do I refer to a database?

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-07-16 : 01:27:05
railway is the name of the database ?

the format is [database name].[schema].[object name]

try railway.dbo.mdb


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

sharankruthi
Starting Member

22 Posts

Posted - 2009-07-16 : 02:01:27
No its not working..
Something like this is working.
Select name from railway.sys.tables
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-07-16 : 02:40:14
what are you looking for ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

sharankruthi
Starting Member

22 Posts

Posted - 2009-07-16 : 02:46:33
I need to display tables in a particular database
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-07-16 : 02:55:03
quote:
I need to display tables in a particular database

You can access sys.tables or INFORMATION_SCHEMA.TABLES for the lists of tables


select *
from [DatabaseName].INFORMATION_SCHEMA.TABLES

or

select *
from [DatabaseName].sys.tables


quote:
select name
from railway.mdb
where name like '#temp%'

you are looking for the temp table ? Or you want to check for the existence of a temp table ?


check for object_id('tempdb..#temp_table') is not null


don't use #temp%. It might return other temp table with similar name. example #temp1, #temp1000

by the way, the temp table is created in database tempdb, not in your railway database. You can find the record in tempdb.sys.tables

if you want to reference tempdb.sys.tables use object_id()

select *
from tempdb.sys.tables
where object_id = object_id('tempdb..#temp')



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

sharankruthi
Starting Member

22 Posts

Posted - 2009-07-16 : 03:13:38
Thankx a lot!!!
Go to Top of Page
   

- Advertisement -