[SQLCop].[test Tables without a primary key]
ChrisGStevens
Posts: 10 Bronze 1
Need to handle the SQL Version differences.
This is the perfect example. [SQLCop].[test Tables without a primary key]
When reviewing the SQLCop failures I noticed that I had Database Users instead of the schema.
The odd thing was these users don't have anything to do with the tables in question so got me looking.
I updated my test to show schemas instead of the users.
This is what comes with SQLTest when you install SQLCop.
This is the perfect example. [SQLCop].[test Tables without a primary key]
When reviewing the SQLCop failures I noticed that I had Database Users instead of the schema.
The odd thing was these users don't have anything to do with the tables in question so got me looking.
I updated my test to show schemas instead of the users.
-- SQL Server 2005 or higher SELECT s.name + '.' + o.name + CHAR(13) + CHAR(10) FROM sys.objects o INNER JOIN sys.schemas s ON o.schema_id = s.schema_id LEFT JOIN (SELECT parent_obj FROM sysobjects WHERE xtype = 'PK') AS PrimaryKeys ON o.object_id = PrimaryKeys.parent_obj WHERE o.type = 'U' AND PrimaryKeys.parent_obj IS NULL AND s.name <> 'tSQLt' ORDER BY s.name, o.name;
This is what comes with SQLTest when you install SQLCop.
-- SQL Server 2000 or Lower, users equaled schemas and that is old school. SELECT su.name + '.' + AllTables.name FROM (SELECT name, id, uid FROM sysobjects WHERE xtype = 'U') AS AllTables INNER JOIN sysusers su ON AllTables.uid = su.uid LEFT JOIN (SELECT parent_obj FROM sysobjects WHERE xtype = 'PK') AS PrimaryKeys ON AllTables.id = PrimaryKeys.parent_obj WHERE PrimaryKeys.parent_obj IS NULL AND su.name <> 'tSQLt' ORDER BY su.name, AllTables.name;
Tagged:
Comments
First, SQL Test does not support SQL 2000.
What version of SQL Test are you using?
What version of SSMS are you using?
Using SQL Test V2.0.4.295 with SSMS 17.3, the version of [SQLCop].[test Tables without a primary key] is as follows:
Many Thanks
Eddie
Senior Product Support Engineer
Redgate Software Ltd
Email: support@red-gate.com
Works like a charm.