schemazen icon indicating copy to clipboard operation
schemazen copied to clipboard

Error when Scripting SQL Server 2008R2 Express database

Open MariaJane opened this issue 7 years ago • 3 comments

Hi, I'm getting the following errors when running the Script option with SQL Server 200R2 EXPRESS

The multi-part identifier "CHECK_CONSTRAINTS.CONSTRAINT_SCHEMA" could not be bound. The multi-part identifier "CHECK_CONSTRAINTS.CONSTRAINT_NAME" could not be bound.

All works well with SQL Server 2012 Express. Thanks.

MariaJane avatar Jul 17 '17 14:07 MariaJane

I'm getting the same error for SQL Server 2008 R2 Standard edition. The database I'm connecting to is not on my local machine. Its via windows authentication on a different machine.

jaybp avatar Apr 12 '18 13:04 jaybp

Did you guys find a solution to make it work for SQL Server 2008?

thfrei avatar Mar 06 '19 13:03 thfrei

I fixed this issue by giving the INFORMATION_SCHEMA.CHECK_CONSTRAINTS part of the query an alias Updated code below:

WITH SysObjectCheckConstraints AS ( SELECT OBJECT_NAME(OBJECT_ID) AS ConstraintName ,SCHEMA_NAME(schema_id) AS SchemaName ,OBJECT_NAME(parent_object_id) AS TableName ,objectproperty(object_id, 'CnstIsNotRepl') AS NotForReplication FROM sys.objects WHERE type_desc = 'CHECK_CONSTRAINT' )

			SELECT CONSTRAINT_CATALOG AS TABLE_CATALOG, CONSTRAINT_SCHEMA AS TABLE_SCHEMA, 
					NotForReplication,
					TableName AS TABLE_NAME, CONSTRAINT_NAME, CHECK_CLAUSE 
			FROM INFORMATION_SCHEMA.CHECK_CONSTRAINTS cs
			INNER JOIN SysObjectCheckConstraints ON 
			SysObjectCheckConstraints.SchemaName = cs.CONSTRAINT_SCHEMA AND
			SysObjectCheckConstraints.ConstraintName = cs.CONSTRAINT_NAME 

DamoDCoder avatar Jun 18 '19 22:06 DamoDCoder