andryosribeiro
(usa Red Hat)
Enviado em 15/12/2021 - 09:54h
Esse seria o script, porém existem vezes que ele não trás resultado nenhum pois a tabela não possuí índices. Então eu queria colocar uma mensagem para quando não trouxer nada. Como eu poderia fazer? Não sei me referir a saída igual a nada ..
tablename=$1
if [ -z $1 ]; then
echo ""
echo "================================================================="
echo "Database Inform: lindex <table_name>" ${tablename}
echo "================================================================="
echo ""
else
echo ""
echo "================================================================="
echo "Table Indexes": ${tablename}
echo "================================================================="
echo ""
$sql -e "SELECT DISTINCT
a.table_name as 'Table',
b.table_rows as 'Table_rows',
ROUND(b.data_free / 1024, 2) AS 'Data_free (KB)',
ROUND(((b.data_length + b.index_length) / 1024), 2) as 'Table_size (KB)',
ROUND(index_length / 1024, 2) as 'Index_size (KB)'
from information_schema.statistics as a
INNER JOIN information_schema.TABLES as b ON a.table_name = b.table_name
where a.table_name = '${tablename}'
GROUP BY 1,2;" 2>/dev/null
echo ""
echo "================================================================="
echo "Non_unique: 0 = unique 1 = non unique"
echo "================================================================="
echo ""
$sql -e "SELECT DISTINCT
a.table_schema as 'Db',
a.table_name as 'Table',
a.index_name as 'Index_name',
a.column_name as 'Column_name',
a.index_type as 'Index_type',
a.seq_in_index as 'Seq_in_index',
a.non_unique as 'Non_unique'
from
information_schema.STATISTICS as a,
information_schema.COLUMNS as b
where a.table_name = '${tablename}' GROUP BY a.column_name
ORDER BY seq_in_index;" 2>/dev/null
fi