1. 程式人生 > 資料庫 >SQL資料庫查詢-模糊查詢表、新增表字段說明、獲取說明

SQL資料庫查詢-模糊查詢表、新增表字段說明、獲取說明

--模糊查詢表
select * from (select
TABLE_NAME from information_schema.tables)
as bc where TABLE_NAME like '%TableName%'
--1、新增表說明
EXECUTE sp_addextendedproperty N'MS_Description','使用者表',N'user',N'dbo',N'table',N'表名稱_User',NULL,NULL
--2、刪除表說明
EXEC sp_dropextendedproperty N'MS_Description','user','dbo','table', '表名稱_User', NULL,NULL

--3.新增欄位說明
EXECUTE sp_addextendedproperty N'MS_Description', '名稱', N'user', N'dbo', N'table', N'Table_User', N'column', N'欄位名稱_name'
--4.刪除欄位說明
EXEC sp_updateextendedproperty 'MS_Description','名稱','user','dbo','table','Table_User','column',N'欄位名稱_name'
--獲取所有表、及表說明
select
a.name AS 表名,
CONVERT(NVARCHAR(100), isnull(g.[value], '')) AS 說明 
from sys.tables a left
join sys.extended_properties g
on (a.object_id = g.major_id AND g.minor_id = 0)
--獲取表字段、及欄位說明
select
c.[name] as 欄位名,
cast(isnull(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 t.name='TableName'