return"select column_name AS COLNAME, ordinal_position AS COLPOSITION, column_default AS DATADEFAULT, is_nullable AS NULLABLE, data_type AS DATATYPE, "+
"character_maximum_length AS DATALENGTH, numeric_precision AS DATAPRECISION, numeric_scale AS DATASCALE, column_key AS COLKEY, column_comment AS COLCOMMENT "+
"from information_schema.columns where table_schema = '"+dbName+"' and table_name = '"+tableName+"' order by ordinal_position ";
}
@Override
publicStringtables(StringdbName){
return"SELECT table_name AS TABLENAME, table_comment AS TABLECOMMENT FROM information_schema.tables where table_schema = '"+dbName+"' ";
return"select columns.column_name AS colName, columns.data_type AS DATATYPE, columns.data_length AS DATALENGTH, columns.data_precision AS DATAPRECISION, "+
"columns.data_scale AS DATASCALE, columns.nullable AS NULLABLE, columns.column_id AS COLPOSITION, columns.data_default AS DATADEFAULT, comments.comments AS COLCOMMENT,"+
"case when t.column_name is null then 0 else 1 end as COLKEY "+
"from sys.user_tab_columns columns LEFT JOIN sys.user_col_comments comments ON columns.table_name = comments.table_name AND columns.column_name = comments.column_name "+
"left join ( "+
"select col.column_name as column_name, con.table_name as table_name from user_constraints con, user_cons_columns col "+
"where con.constraint_name = col.constraint_name and con.constraint_type = 'P' "+
") t on t.table_name = columns.table_name and columns.column_name = t.column_name "+
"where columns.table_name = UPPER('"+tableName+"') order by columns.column_id ";
}
@Override
publicStringtables(StringdbName){
return"select tables.table_name AS TABLENAME, comments.comments AS TABLECOMMENT from sys.user_tables tables "+
"LEFT JOIN sys.user_tab_comments comments ON tables.table_name = comments.table_name ";
return"select col.column_name AS COLNAME, col.ordinal_position AS COLPOSITION, col.column_default AS DATADEFAULT, col.is_nullable AS NULLABLE, col.udt_name AS DATATYPE, "+
"col.character_maximum_length AS DATALENGTH, col.numeric_precision AS DATAPRECISION, col.numeric_scale AS DATASCALE, des.description AS COLCOMMENT, "+
"case when t.colname is null then 0 else 1 end as COLKEY "+
"from information_schema.columns col left join pg_description des on col.table_name::regclass = des.objoid and col.ordinal_position = des.objsubid "+
"left join ( "+
"select pg_attribute.attname as colname from pg_constraint inner join pg_class on pg_constraint.conrelid = pg_class.oid "+
"inner join pg_attribute on pg_attribute.attrelid = pg_class.oid and pg_attribute.attnum = any(pg_constraint.conkey) "+
"where pg_class.relname = '"+tableName+"' and pg_constraint.contype = 'p' "+
") t on t.colname = col.column_name "+
"where col.table_catalog = '"+dbName+"' and col.table_schema = 'public' and col.table_name = '"+tableName+"' order by col.ordinal_position ";
}
@Override
publicStringtables(StringdbName){
return"select relname AS TABLENAME, cast(obj_description(relfilenode, 'pg_class') as varchar) AS TABLECOMMENT from pg_class "+
"where relname in (select tablename from pg_tables where schemaname = 'public' and tableowner = '"+dbName+"' and position('_2' in tablename) = 0) ";
return"select columns.name AS colName, columns.column_id AS COLPOSITION, columns.max_length AS DATALENGTH, columns.precision AS DATAPRECISION, columns.scale AS DATASCALE, "+
"columns.is_nullable AS NULLABLE, types.name AS DATATYPE, CAST(ep.value AS NVARCHAR(128)) AS COLCOMMENT, e.text AS DATADEFAULT, "+
"(select top 1 ind.is_primary_key from sys.index_columns ic left join sys.indexes ind on ic.object_id = ind.object_id and ic.index_id = ind.index_id and ind.name like 'PK_%' where ic.object_id=columns.object_id and ic.column_id=columns.column_id) AS COLKEY "+
"from sys.columns columns LEFT JOIN sys.types types ON columns.system_type_id = types.system_type_id "+
"LEFT JOIN syscomments e ON columns.default_object_id= e.id "+
"LEFT JOIN sys.extended_properties ep ON ep.major_id = columns.object_id AND ep.minor_id = columns.column_id AND ep.name = 'MS_Description' "+
"where columns.object_id = object_id('"+tableName+"') order by columns.column_id ";
}
@Override
publicStringtables(StringdbName){
return"select tables.name AS TABLENAME, CAST(ep.value AS NVARCHAR(128)) AS TABLECOMMENT "+
"from sys.tables tables LEFT JOIN sys.extended_properties ep ON ep.major_id = tables.object_id AND ep.minor_id = 0";