Is there a way to list all SQL Server CE database table indexes, or at least for individual tables?
-- Retrieves information about the indexes contained in the database.
SELECT * FROM
INFORMATION_SCHEMA.INDEXES
-- Retrieves all the Tables in the database including the System tables.
SELECT * FROM
INFORMATION_SCHEMA.TABLES
Arjuna Chiththananda - Retrieving Schema Information of SQL CE Database
Thank you Arjuna! you pointed me in the right direction..... The following works.
SELECT 'Y' FROM INFORMATION_SCHEMA.INDEXES
where table_name = 'PP_JOB_TICKET_LIVE'
and index_name = 'PP_JOB_TICKET_LIVE_PK'
Thanks so much for your time.
Related
I have a database with over a 150 tables. I need to be able to find every table that has a column called EmployeeID. Is there a way for me to find all tables that have this column? It's kind of a long process if I go through each table and try to find if it has that column.
Use INFORMATION_SCHEMA.COLUMNS:
select c.*
from INFORMATION_SCHEMA.COLUMNS c
where column_name = 'EmployeeID';
I am using SQL Server 2005. I am trying to SELECT a list of tables in one of my database. Here is my structure of my SQL Server:
- <IP>(SQL Server 9.0 -userlogin)
- Databases
- Company
- Tables
- dbo.UserDB
- dbo.detailsDB
- dbo.goodsDB
I would like to retrieve the values of dbo.UserDB, dbo.detailsDB, dbo.goodsDB
But i do not know what is the exact sql query needed.
I have tried many ways like
SELECT * FROM userlogin.Tables; and
SELECT * FROM userlogin.Company.Tables;, but none of them works.
I have seen quite a few posts which suggests using show databases and show tables, but they don't seem to work as well.
Is it possible to select a list of table names in a database in the first place?
Thank you for any help in advance.
Thanks for the MSDNA link that #TomTom provided, I can now list my tables in my database.
However, I would want to list specific tables where TABLE_NAME contains "user".
How can I do it? I am trying on the following sql but it is not displaying result at the moment:
SELECT DISTINCT TABLE_NAME
FROM Company.INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME LIKE '%"user"%';
GO
Try the iNFORMATION_SCHEMA.
http://msdn.microsoft.com/en-us/library/ms186778.aspx
They contain all the schema information you need.
Use the new sys system catalog in SQL Server 2005 and up:
SELECT Name
FROM sys.tables
WHERE is_ms_shipped = 0 -- only list *your* tables - not the system / MS table
You can read more about system catalog views and how to query them in the MSDN Books Online - and be warned - there's lots more to read and learn!
You could use this
Use ***database name***
SELECT *
FROM sys.tables
WHERE name like '%user%'
Sorry, have seen that #marc_s has provided the answer before me!
You can use INFORMATION_SCHEMA as told by #TomTom:
USE <<YOUR_DB_NAME>>
SELECT TABLE_SCHEMA + '.' + TABLE_NAME, *
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE'
ORDER BY TABLE_SCHEMA + '.' + TABLE_NAME
You can customize above query as per your requirements.
For your other question to find tables where the name contains 'user', execute the following statement:
USE <<YOUR_DB_NAME>>
Exec sp_tables '%user%'
Try:
SELECT *
from sysobjects
where type = 'U' AND
NAME LIKE '%user%'
GO
Please suggest me a query to find temp database tables.
select name from tempdb.sys.tables
All temp tables created are stored in the tempdb available on sql server. So run this query in tempdb, you will find available temp tables on the server -
select * from sysobjects where "xtype" = 'u'
Hope this will help you
In SQL Server, there are some DMVs that appear in all databases and have the same content in it. What's the purpose of this approach? For example, the following 2 query will give the same result.
select *
from master.sys.databases
select *
from tempdb.sys.databases
Thanks.
sys.databases only exists once (actually in the hidden resource database)
All you are doing above is switching db context temporarily by using a 3 part object name
How to find what are all tables has binary data and display the table name ?
For MySql you want the INFORMATION_SCHEMA COLUMNS table:
http://dev.mysql.com/doc/refman/5.1/en/columns-table.html
If you need to find all of the tables which have binary columns, then you can create a query joining with the INFORMATION_SCHEMA TABLES table:
http://dev.mysql.com/doc/refman/5.1/en/tables-table.html
That depends a lot on what database you are using. Many databases (at least MySQL and PostgreSQL, maybe all) has a database called information_schema (or something similar). This is a database describing the structure of your databases along with all tables, their fields and what types of data the fields hold. So this would be a good starting point.
I'd need to know which database, but this (or something very similar) should work on Oracle:
select *
from all_tab_columns
where data_type in ('BLOB', 'RAW')
;
you need to select the system tables (in msssql 2000 - syscolumns) or system management views (in mssql 2005 or 2008 - sys.columns) to find the columns with system_type_id you need to find, and then find the corresponding table joining sys.columns and sys.objects by object_id field.
Can you ask the DBA or the DB-developper?
if no, what DB (Oracle, MySql, Microsoft, other?) are you using ..
EDITED for MySQL DB
Use
select table_schema
, table_name
, column_name
, data_type
from information_schema
where data_type like '%blob%'
or data_type in ('binary','varbinary')