使用数据类型、约束和主键标志检索表列信息
获取表中列的详细列表以及它们的数据类型、是否允许空值、是否为主键,可以使用以下 SQL Server 查询使用:
SELECT c.name AS 'Column Name', t.Name AS 'Data Type', c.max_length AS 'Max Length', c.precision, c.scale, c.is_nullable, ISNULL(i.is_primary_key, 0) AS 'Primary Key' FROM sys.columns c INNER JOIN sys.types t ON c.user_type_id = t.user_type_id LEFT OUTER JOIN sys.index_columns ic ON ic.object_id = c.object_id AND ic.column_id = c.column_id LEFT OUTER JOIN sys.indexes i ON ic.object_id = i.object_id AND ic.index_id = i.index_id WHERE c.object_id = OBJECT_ID('YourTableName')
在此查询中,将 'YourTableName' 替换为目标表的实际名称。如果表位于架构中,请将 'YourTableName' 替换为 '(YourSchemaName}.YourTableName)'。
说明:
以上是如何在SQL Server中检索详细的表列信息?的详细内容。更多信息请关注PHP中文网其他相关文章!