SQL Server數(shù)據(jù)庫字段說明的添加修改刪除示例
作者:yinxiaoqi
本文我們主要介紹了SQL Server數(shù)據(jù)庫字段說明的添加、修改和刪除的代碼示例,還順便介紹了查詢數(shù)據(jù)庫字段信息和類型的操作代碼示例,希望能夠?qū)δ兴鶐椭?/div>
SQL Server數(shù)據(jù)庫字段說明的添加、修改和刪除以及查詢數(shù)據(jù)庫字段信息和類型的操作示例是本文我們主要要介紹的,接下來我們就開始一一介紹這部分內(nèi)容,希望能夠?qū)δ兴鶐椭?/p>
1.查詢兩個表的字段說明
- SELECT t.[name] AS [表名],c.[name] AS [字段名],cast(ep.[value]
- as varchar(100)) AS [字段說明]
- FROM sys.tables AS t INNER JOIN sys.columns
- AS c ON t.object_id = c.object_id LEFT JOIN sys.extended_properties AS ep
- ON ep.major_id = c.object_id AND ep.minor_id = c.column_id WHERE ep.class =1
- and t.[name]='table1' or t.[name]='table2'
- and c.[name] in ('table2字段','table2字段')
- or c.[name] in ('table1字段,'table1字段')
2.添加字段的名稱
- EXEC
- sys.sp_addextendedproperty @name=N'MS_Description',
- @value=N'字段說明' , @level0type=N'SCHEMA',@level0name=N'dbo',
- @level1type=N'TABLE',@level1name=N'表名', @level2type=N'COLUMN',
- @level2name=N'字段名'
- GO
3.修改字段的名稱
- BEGIN TRANSACTION
- GO
- DECLARE @v sql_variant
- SET @v = N'說明信息'
- EXECUTE sys.sp_updateextendedproperty N'MS_Description',
- @v, N'SCHEMA',N'dbo',N'TABLE',N'表名, N'COLUMN', N'字段名'
- GO
- COMMIT
4.查詢數(shù)據(jù)庫字段信息和類型
- select a.name as zdname,a.length,b.name as zdtype from syscolumns a,systypes b,sysobjects c
- where a.xtype=b.xtype and a.id=c.id and c.name= 'table' --沒有過濾系統(tǒng)字段信息
- select a.name,a.length,b.name from syscolumns a,systypes b,sysobjects c
- where a.xtype=b.xtype and a.id=c.id and c.name= 'table'
- AND B.NAME!='SYSNAME' --過濾了系統(tǒng)字段信息
- select a.name,a.length,b.name from syscolumns a,systypes b,sysobjects c
- where a.xtype=b.xtype and a.id=c.id and c.name= 'table' and charindex('sysname',b.name) = 0
- --過濾了系統(tǒng)字段信息
以上就是SQL Server數(shù)據(jù)庫字段說明的添加、修改和刪除操作的代碼示例的全部內(nèi)容,本文就介紹到這里了,希望本次的介紹能夠?qū)δ兴斋@!
【編輯推薦】
責任編輯:趙鵬
來源:
CSDN博客


相關(guān)推薦




