schemazen
schemazen copied to clipboard
Error when Scripting SQL Server 2008R2 Express database
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.
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.
Did you guys find a solution to make it work for SQL Server 2008?
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