I am connecting to Microsoft SQL Server using Oracle SQL Developer.
Describe table-name is not giving me any results. Can anyone please help me out with the right command to use to view SQL Server table structure in Oracle SQL developer?
Try this:
-- custom table information
select schema_name(t.schema_id)+'.'+t.name as TableName,
t.*
from sys.tables t
where t.name = 'MyTableName'
-- table columns information
select schema_name(t.schema_id)+'.'+t.name as TableName,
TYPE_NAME(t2.system_type_id) as DataType,
t2.*
from sys.tables t
inner join sys.columns t2 on t2.object_id = t.object_id
where t.name = 'MyTableName'
order by 1,
t2.column_id
Or this:
-- custom table information
exec sp_help 'MyTableName'
-- table columns information
exec sp_columns 'MyTableName'
DESC is an Oracle client command - works in SQLPlus, SQLcl, and SQL Developer - WHEN connected to an Oracle Database.
The best we have to offer you is, open the table from your browser, and see the Columns page.
Or like someone has offered, write query or use the provided SP that MSFT gives you.
Thank you guys for your answers. I have found one more method which is below
select * from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME='XX_TABLE_NAME';
Thought of sharing as it might be helpful for others
Shift + F4
or Right click on tablename and click on popup Describe
Related
How to find the database name for a particular table when we have created a table and we forgot the database where we have created the same.
I have found the solution, we can simply find a database where we have created the table.
SELECT DISTINCT DB_NAME(database_id)
FROM [sys].[dm_db_index_operational_stats](NULL,NULL,NULL,NULL)
WHERE OBJECT_NAME(object_id,database_id) = 'tablename'
Try this EXEC sp_MSforeachdb
EXEC sp_MSforeachdb 'USE ? SELECT sc.TABLE_CATALOG, sc.TABLE_SCHEMA, sc.TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNS sc WHERE TABLE_NAME=''YourTableName'''
if you are using SQL Server 2012 or more then simply you can find DataBase name using INFORMATION_SCHEMA like
SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME ='your_table_name'
Here TABLE_CATALOG column shows DataBase Name.
There is no SQL Server ready solution to your problem.
To resolve it you need to loop through each database and to put the information schema into new table and then to query it.
Some idea can be found in the site bellow:
https://blog.sqlauthority.com/2008/04/29/sql-server-find-table-in-every-database-of-sql-server/
I am using sql server connections in sql developer with the help of a plug-in...
Now my question is I have a list of tables which belong to sql server connections but I don't have the information on, which table belongs to which schema?
I have tried using the script
select owner, table_name
from all_tables
where table_name like 'xxxxxxxx%';
but it didn't work out, can any one please help out on this???
Thanks in advance!!!
Select schema_name (schema_id), name
from sys.tables
where name like 'your pattern'
#Ben Thul has an answer that is absolutely fine.
This is just an alternative using INFORMATION_SCHEMA (both of which essentially use sys.objects under the hood):
SELECT
t.TABLE_CATALOG
,t.TABLE_SCHEMA
,t.TABLE_NAME
,t.TABLE_TYPE
FROM INFORMATION_SCHEMA.TABLES t
WHERE t.TABLE_NAME LIKE '%<YOUTABLE>%'
I somehow managed to create a table in a database with a null table schema.
I can't query the table since it has no owner, and altering the table doesn't work for the same reason.
I would alter the table using:
ALTER SCHEMA null TRANSFER dbo.SubscriptionAnswerMR
But that doesn't work.
The information_schema.tables looks like this:
TABLE_CATALOG TABLE_SCHEMA TABLE_NAME TABLE_TYPE
q_Profiles NULL SubscriptionAnswerMR BASE TABLE
So my question is: How do I change q_Profiles' table_schema?
SQL Server 2000 (edit)
Microsoft SQL Server Management Studio 2008R2
You should be able to verify that your table is fine by seeing the result of the following query:
SELECT u.name
FROM q_Profiles..sysobjects AS o
INNER JOIN q_Profiles..sysusers AS u
ON o.uid = u.uid
WHERE o.name = 'SubscriptionAnswerMR';
This should be dbo unless someone explicitly created them with a different owner or used sp_changeobjectowner. Which you can use if you find that sysobjects also has the wrong answer:
EXEC sp_changeobjectowner 'SubscriptionAnswerMR', 'dbo';
ALTER SCHEMA is not valid here because it was introduced in SQL Server 2005. Though it would be useful for you to describe what "doesn't work" means.
INFORMATION_SCHEMA is a horribly unreliable set of views as #Pondlife points out. Also see the following, which doesn't help you much in SQL Server 2000, but should help going forward:
The case against INFORMATION_SCHEMA views
Also as a side note you seem to be confused about tables and database. TABLE_CATALOG is the database, not the table.
Did you note this comment in the documentation?
Do not use INFORMATION_SCHEMA views to determine the schema of an
object. The only reliable way to find the schema of a object is to
query the sys.objects catalog view or use the OBJECT_SCHEMA_NAME
function.
How can we find which table is locked in the database? Please, suggest.
You can use sp_lock (and sp_lock2), but in SQL Server 2005 onwards this is being deprecated in favour of querying sys.dm_tran_locks:
select
object_name(p.object_id) as TableName,
resource_type, resource_description
from
sys.dm_tran_locks l
join sys.partitions p on l.resource_associated_entity_id = p.hobt_id
sp_lock
When reading sp_lock information, use the OBJECT_NAME( ) function to get the name of a table from its ID number, for example:
SELECT object_name(16003073)
EDIT :
There is another proc provided by microsoft which reports objects without the ID translation : http://support.microsoft.com/kb/q255596/
I exported a table to a server but I can't find the table. Maybe I didn't put the right destination database. How can I find this table if my server has multiple databases, without opening each one of them?
I use MS Sql Server Management Studio 2008.
Rough and dirty, but it would do the job.
-- Instructions. Replace "table_name_here" with actual table name
sp_MSforeachdb 'USE ?
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N''[table_name_here]'') AND OBJECTPROPERTY(id, N''IsUserTable'') = 1)
BEGIN
PRINT ''Found in db ?''
END'
One way
SELECT DISTINCT DB_NAME(database_id)
FROM [sys].[dm_db_index_operational_stats](NULL,NULL,NULL,NULL)
WHERE OBJECT_NAME(object_id,database_id) = 'table_name'
Or if you are reasonably confident it would be in the dbo schema in whichever database
SELECT name
FROM sys.databases
WHERE CASE
WHEN state_desc = 'ONLINE'
THEN OBJECT_ID(QUOTENAME(name) + '.[dbo].[table_name]', 'U')
END IS NOT NULL
Based off Martin Smith's answer above but generalised into a view to give a sort of cross-DB version of sys.tables -
CREATE VIEW ListTablesAllDBs
AS
SELECT
DB_NAME(database_id) as DBName,
OBJECT_SCHEMA_NAME(object_id,database_id) as SchemaName,
OBJECT_NAME(object_id,database_id) as TableName
FROM
[sys].[dm_db_index_operational_stats](NULL,NULL,NULL,NULL)
Now, if only I can work out a way to do the same for columns.......
EDIT - Ignore this, finding it sometimes misses tables altogether.
Minor clarification just to avoid headaches for those with 'SuperUsers' who don't know how to name DBs:
EXEC sp_MSForEachDB '
USE [?]
IF OBJECT_ID(''mytable'') IS NOT NULL AND
OBJECTPROPERTY(OBJECT_ID(''mytable''), ''IsTable'') = 1
PRINT ''Found here: ?'''
select 'select * from '+name+'.sys.tables where name=
''[yourtable]'';' from sys.databases
Instead of [yourtable], type the name of the missing table, and run the result again.
EXEC sp_MSForEachDB '
USE ?
IF OBJECT_ID(''mytable'') IS NOT NULL AND
OBJECTPROPERTY(OBJECT_ID(''mytable''), ''IsTable'') = 1
PRINT ''?''
'