S.P

导航

Mono的资源

Posted on 2012-04-26 13:28  S.P  阅读(211)  评论(0)    收藏  举报

最近在研究.NET framework的底层,用MONO的开源来学习是一个不错的选择。

这里就权当做做笔记吧

 

mono-2.11.1\mcs\class\System.Data.Linq\src\DbLinq.SqlServer\SqlServerSchemaLoader.cs

加载SqlServer的结构, 有用到的sql:

-- 获取数据库的所有外键关系
SELECT rc.CONSTRAINT_NAME AS 'CONSTRAINT_NAME', 'FOREIGN KEY' AS 'CONSTRAINT_TYPE', rcu_from.TABLE_NAME AS 'TABLE_NAME', rcu_from.TABLE_SCHEMA AS 'TABLE_SCHEMA', rcu_from.COLUMN_NAME AS 'FKEY_FROM_COLUMN', rcu_to.TABLE_SCHEMA AS 'FKEY_TO_SCHEMA', rcu_to.TABLE_NAME AS 'FKEY_TO_TABLE', rcu_to.COLUMN_NAME AS 'FKEY_TO_COLUMN' FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS rc INNER JOIN INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE rcu_from ON rc.CONSTRAINT_CATALOG = rcu_from.CONSTRAINT_CATALOG AND rc.CONSTRAINT_NAME = rcu_from.CONSTRAINT_NAME INNER JOIN INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE rcu_to ON rc.UNIQUE_CONSTRAINT_CATALOG = rcu_to.CONSTRAINT_CATALOG AND rc.UNIQUE_CONSTRAINT_NAME = rcu_to.CONSTRAINT_NAME

 

-- 获取所有的字段名
SELECT columns.TABLE_CATALOG, columns.TABLE_SCHEMA, columns.TABLE_NAME, columns.COLUMN_NAME, columns.ORDINAL_POSITION, columns.COLUMN_DEFAULT, (SELECT CAST (COUNT(*) AS BIT) FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS rc INNER JOIN INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE rcu ON rc.CONSTRAINT_CATALOG = rcu.CONSTRAINT_CATALOG AND rc.CONSTRAINT_NAME = rcu.CONSTRAINT_NAME WHERE rc.CONSTRAINT_TYPE = 'PRIMARY KEY' AND rc.TABLE_CATALOG = columns.TABLE_CATALOG AND rc.TABLE_SCHEMA = columns.TABLE_SCHEMA AND rc.TABLE_NAME = columns.TABLE_NAME AND rcu.COLUMN_NAME = columns.COLUMN_NAME ) AS 'PRIMARY_KEY', columns.IS_NULLABLE, columns.DATA_TYPE, columns.CHARACTER_MAXIMUM_LENGTH, columns.CHARACTER_OCTET_LENGTH, CAST(columns.NUMERIC_PRECISION AS INT) AS 'NUMERIC_PRECISION', columns.NUMERIC_PRECISION_RADIX, columns.NUMERIC_SCALE, columns.DATETIME_PRECISION, columns.CHARACTER_SET_CATALOG, columns.CHARACTER_SET_SCHEMA, columns.CHARACTER_SET_NAME, columns.COLLATION_CATALOG FROM INFORMATION_SCHEMA.COLUMNS columns ORDER BY columns.TABLE_CATALOG, columns.TABLE_SCHEMA, columns.TABLE_NAME, columns.COLUMN_NAME