Sql server 2005: informazioni su tabelle e campi
{ Posted on lug 04 2011 by maury }
In Sql server a volte sembra non proprio agevole recuperare la struttura di una tabella o altre informazioni sui campi… le seguenti query rendono invece il compito molto semplice
Elenca tutte le tabelle del Database
SELECT * FROM sys.Tables
Elenca tutte le informazioni sulla tabella TABLENAME
EXEC sp_help 'TABLENAME'
Elenca le colonne della tabella TABLENAME
EXEC sp_columns 'TABLENAME'
Elenca alcune informazioni sulle colonne della tabella TABLENAME
SELECT table_name, ordinal_position, column_name, data_type, is_nullable,character_maximum_length FROM information_schema.COLUMNS WHERE table_name LIKE '%TABLENAME%' ORDER BY ordinal_position
Elenca spazio e righe di ogni tabella
qui usiamo la stored procedure non documentata ‘sp_MSforeachtable’
EXEC sp_MSforeachtable @command1="EXEC sp_spaceused '?'"

Everybody is a genius. But if you judge a fish by its ability to climb a tree, it will live its whole life believing that it is stupid (Albert Einstein)
