菜单

UNION过滤重复记录语句并取得不重复的数据,获取MSSQL数据字典的SQL语句

2020年1月11日 - 数据网络

//大家日常是用union all 改成union看一下,联合查询展现不重复的记录哦。

复制代码 代码如下:CREATE VIEW
dbo.vw_db_dictionary AS SELECT TOP 100 PERCENT dbo.sysobjects.name AS
table_name, dbo.sysproperties.[value] AS table_desc,
dbo.syscolumns.name AS field, properties.[value] AS field_desc,
dbo.systypes.name AS field_type, dbo.syscolumns.length AS field_size,
ISNULL(COLUMNPROPERTY(dbo.syscolumns.id, dbo.syscolumns.name, ‘Scale’),
0) AS field_precision, dbo.syscolumns.isnullable AS nullable, CASE WHEN
syscomments.text IS NULL THEN ” ELSE syscomments.text END AS
default_value, CASE WHEN COLUMNPROPERTY(syscolumns.id, syscolumns.name,
‘IsIdentity’) = 1 THEN ‘√’ ELSE ” END AS is_identity, CASE WHEN EXISTS
(SELECT 1 FROM sysobjects WHERE xtype = ‘PK’ AND name IN (SELECT name
FROM sysindexes WHERE indid IN (SELECT indid FROM sysindexkeys WHERE id
= syscolumns.id AND colid = syscolumns.colid))) THEN ‘√’ ELSE ” END AS
is_key FROM dbo.syscolumns INNER JOIN dbo.sysobjects ON
dbo.sysobjects.id = dbo.syscolumns.id INNER JOIN dbo.systypes ON
dbo.syscolumns.xtype = dbo.systypes.xtype LEFT OUTER JOIN
dbo.sysproperties properties ON dbo.syscolumns.id = properties.id AND
dbo.syscolumns.colid = properties.smallid LEFT OUTER JOIN
dbo.sysproperties ON dbo.sysobjects.id = dbo.sysproperties.id AND
dbo.sysproperties.smallid = 0 LEFT OUTER JOIN dbo.syscomments ON
dbo.syscolumns.cdefault = dbo.syscomments.id WHERE (dbo.sysobjects.xtype
= ‘U’) ORDER BY dbo.sysobjects.name

sql UNION过滤重复记录语句并得到不另行的数目

$sql =UNION
ALL-UNION———————-以下句子怎么着拿到不另行的数量?SELECT
DISTINCT TOP 100 PERCENT kirinLDS.dbo.tbl职员调解.部门名 AS 部门名FROM
kirinLDS.dbo.tbl职员 INNE奥德赛 JOIN kirinLDS.dbo.tbl定单 ON
kirinLDS.dbo.tbl职员.工号 = kirinLDS.dbo.tbl定单.业务员 INNETucson JOIN
kirinLDS.dbo.tbl人士调治 ON kirinLDS.dbo.tbl人员.姓名 =
kirinLDS.dbo.tbl职员调度.人士WHERE (LEFT(kirinLDS.dbo.tbl定单.会计月, 4)= ‘2008’State of Qatar

UNION

相关文章

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图