如何读取表
该类库使用SQL语句读取表的所有列,使用某些本机存储过程检查数据库中是否存在表,并读取所有表以及表之间的所有关系。
--This stored procedure"sp_tables" is native in the SQL Serversp_tables @table_type = "'TABLE'", @table_name='The name of the Table to be checked'
--This Sql Satatement returns all the columns of a certain table.SELECT c.COLUMN_NAME, c.IS_NULLABLE, c.DATA_TYPE, c.CHARACTER_MAXIMUM_LENGTH, tc.CONSTRAINT_TYPE, COLUMNPROPERTY(OBJECT_ID(c.TABLE_NAME), c.COLUMN_NAME, 'IsIdentity') AS IS_AUTOINCREMENT, COLUMN_DEFAULT FROM INFORMATION_SCHEMA.COLUMNS c LEFTJOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE kcu on c.COLUMN_NAME = kcu.COLUMN_NAME AND c.TABLE_NAME = kcu.TABLE_NAME LEFTJOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc on kcu.CONSTRAINT_NAME = tc.CONSTRAINT_NAME WHERE c.TABLE_NAME = 'The name of the Table to be read'BY c.ORDINAL_POSITION
--The same stored procedure used to check if a table exists,--if the parameter"@table_name" is not used,--it returns all the tables in the databasesp_tables @table_type = "'TABLE'"
sp_fkeys @pktable_name = 'Primary Table', @fktable_name = 'Foreign Table'
相关文章