Herkese merhaba,
Bu kısımda SQL Server’da tabloya ait kolon bilgilerini öğrenme kodları olacak.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
DECLARE @TableName sysname = 'Categories' SELECT DB_NAME() as [Database Name], s.name as [Schema Name], t.name as [Table Name], c.name as [Column Name], ty.name as [Column Data Type], uty.name as [Column System Type], c.max_length as [Column Maximum Length], c.precision as [Column Precision], c.scale as [Column Scale], CASE c.is_nullable WHEN 1 THEN 'Yes' WHEN 0 THEN 'No' END as [Column Is Nullable], CASE c.is_identity WHEN 1 THEN 'Yes' WHEN 0 THEN 'No' END as [Column Has Identity], CASE c.is_computed WHEN 1 THEN 'Yes' WHEN 0 THEN 'No' END as [Column Is Computed], cc.definition as [Computed Column Definition] FROM sys.tables as t INNER JOIN sys.schemas as s ON t.schema_id = s.schema_id INNER JOIN sys.columns as c ON t.object_id = c.object_id INNER JOIN sys.types as ty ON ty.user_type_id = c.user_type_id INNER JOIN sys.types as uty ON ty.system_type_id = uty.user_type_id LEFT JOIN sys.computed_columns as cc ON t.object_id = cc.object_id AND cc.column_id = c.column_id WHERE t.name = @TableName OR @TableName IS NULL UNION ALL SELECT DB_NAME() as DatabaseName, s.name as SchemaName, t.name as TableName, c.name as ColumnName, ty.name as ColumnDataType, ty.name as ColumnSystemTypeName, c.max_length as ColumnMaximumLength, c.precision as ColumnPrecision, c.scale as ColumnScale, CASE c.is_nullable WHEN 1 THEN 'Yes' WHEN 0 THEN 'No' END as ColumnIsNullable, CASE c.is_identity WHEN 1 THEN 'Yes' WHEN 0 THEN 'No' END as ColumnHasIdentity, CASE c.is_computed WHEN 1 THEN 'Yes' WHEN 0 THEN 'No' END as ColumnIsComputed, cc.definition as [Computed Column Definition] FROM sys.tables as t INNER JOIN sys.schemas as s ON t.schema_id = s.schema_id INNER JOIN sys.columns as c ON t.object_id = c.object_id INNER JOIN sys.types as ty ON ty.user_type_id = c.user_type_id AND ty.is_assembly_type = 1 LEFT JOIN sys.computed_columns as cc ON t.object_id = cc.object_id AND cc.column_id = c.column_id WHERE t.name = @TableName OR @TableName IS NULL |
