Archive for octobre 2005
Convertir un type String en Enum
enum EngineType {
unknow,
access,
db2,
mysql,
odbc,
oledb,
oracle,
postgre,
sqlserver
}
string cnxTypeString = "mysql";
EngineType cnxTypeEngine = EngineType.unknow;
if (Enum.IsDefined(typeof(EngineType), cnxTypeString)) {
cnxTypeEngine = (EngineType) Enum.Parse(typeof(EngineType), cnxTypeString, true);
}
(Publié à l’origine sur http://www.bigbold.com/snippets/posts/show/824)
Structure d’une table PostgreSQL depuis Information_Schema
SELECT COLUMN_NAME,
DATA_TYPE,
CHARACTER_MAXIMUM_LENGTH,
NUMERIC_PRECISION,
NUMERIC_SCALE,
IS_NULLABLE,
SUBSTR(COALESCE(COLUMN_DEFAULT, '' ), 1, 8 ) = 'nextval(' AS IS_AUTOINCREMENT,
COLUMN_DEFAULT
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'xxxxxxxx'
ORDER BY ORDINAL_POSITION
(Publié à l’origine sur http://www.bigbold.com/snippets/posts/show/816)
SELECT COLUMN_NAME,
DATA_TYPE,
CHARACTER_MAXIMUM_LENGTH,
NUMERIC_PRECISION,
NUMERIC_SCALE,
IS_NULLABLE,
COLUMNPROPERTY(OBJECT_ID(TABLE_NAME), COLUMN_NAME, 'IsIdentity') AS IS_AUTOINCREMENT,
COLUMN_DEFAULT
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'xxxxxxxx'
ORDER BY ORDINAL_POSITION
(Publié à l’origine sur http://www.bigbold.com/snippets/posts/show/815)
Edit : Voir aussi « system_function_schema.fn_datadictionary« , une fonction qui renvoie le dictionnaire de données pour n’importe quelle base Sql Server.