How to get a list of all AAI database tables, constraints, and indices?
search cancel

How to get a list of all AAI database tables, constraints, and indices?

book

Article ID: 420917

calendar_today

Updated On:

Products

Automation Analytics & Intelligence

Issue/Introduction

When working with AAI Broadcom Support, there may be a need to gather information about your database such as a list of tables, constraints, and indices.

This document will provide queries that can be run by you or your DBA to gather this information.

Environment

AAI

Resolution

Below are a list of queries that can be run to provide this information.

Please provide all output in .csv output.

Oracle

--List of tables

select table_name as tableName, column_name as columnName, data_type as dataType, data_length as colSize
from cols
order by table_name, column_name, data_type, data_length

 

--List of constraints (Update owner with your AAI database username)

select CONSTRAINT_NAME as constraintName, TABLE_NAME as tableName, CONSTRAINT_TYPE as constraintType
from user_constraints
where owner ='INSERT_AAI_DB_USER' and CONSTRAINT_TYPE not in ( 'C', 'U')
order by constraintName, tableName, constraintType

 

--List of indices

select index_name as indexName, table_name as tableName, column_name as columnName
from sys.user_ind_columns
where INDEX_NAME not like 'XPK%'
order by index_name, table_name, columnName

 

SQL Server

--List of tables

select tb.name as tableName, c.name as columnName, t.name as dataType, c.max_length as colSize
from sys.columns c inner join sys.types t on c.system_type_id = t.system_type_id join sys.tables tb on c.object_id=tb.object_id
where t.Name != 'sysname'
order by tableName, columnName, dataType, colSize

 

--List of constraints

select object_name(object_id) as constraintName, object_name(parent_object_id) as tableName, type_desc as constraintType
from sys.objects
where type_desc like '%constraint' and type != 'D'
order by constraintName

 

--List of indices

select i.name as indexName, o.name as tableName, co.[name] as columnName
from sys.indexes i
join sys.objects o on i.object_id = o.object_id
join sys.index_columns ic on ic.object_id = i.object_id
and ic.index_id = i.index_id
join sys.columns co on co.object_id = i.object_id
and co.column_id = ic.column_id
where i.name not like 'XPK%' and o.type_desc='USER_TABLE'
order by indexName, tableName, columnName