Hello,
I am trying to write a query that will generate the script to drop a
constraint. The problem is that I need to get the SCHEMA name from one of
the system views to join with the query below.
This query produces the column schema_id
SELECT * FROM sys.tables
Any help would be appreciated.
sck10
SELECT
Tsyst.schema_id,
Tsyst.name AS 'TableName',
Tsyst.object_id AS 'ObjectID',
Tsyso.name AS 'DefaultName',
Tsyso.type_desc AS 'TypeDscr',
'ALTER TABLE schemaname.' + Tsyst.name + ' DROP CONSTRAINT ' + Tsyso.name
FROM
sys.tables Tsyst
INNER JOIN sys.objects Tsyso
ON Tsyst.object_id = Tsyso.parent_object_id
WHERE (Tsyso.type = 'D')Thanks, but I think I figured it out:
SELECT
Tschema.name AS 'Schema Name',
Tsyst.schema_id,
Tsyst.name AS 'TableName',
Tsyst.object_id AS 'ObjectID',
Tsyso.name AS 'DefaultName',
Tsyso.type_desc AS 'TypeDscr',
'ALTER TABLE schemaname.' + Tsyst.name + ' DROP CONSTRAINT ' + Tsyso.name
FROM
sys.tables Tsyst
INNER JOIN sys.objects Tsyso
ON Tsyst.object_id = Tsyso.parent_object_id
INNER JOIN sys.schemas Tschema
ON Tsyst.schema_id = Tschema.schema_id
WHERE (Tsyso.type = 'D')
"sck10" <sck10@.online.nospam> wrote in message
news:eWQDGA$QHHA.1180@.TK2MSFTNGP05.phx.gbl...
> Hello,
> I am trying to write a query that will generate the script to drop a
> constraint. The problem is that I need to get the SCHEMA name from one of
> the system views to join with the query below.
> This query produces the column schema_id
> SELECT * FROM sys.tables
> Any help would be appreciated.
> sck10
> SELECT
> Tsyst.schema_id,
> Tsyst.name AS 'TableName',
> Tsyst.object_id AS 'ObjectID',
> Tsyso.name AS 'DefaultName',
> Tsyso.type_desc AS 'TypeDscr',
> 'ALTER TABLE schemaname.' + Tsyst.name + ' DROP CONSTRAINT ' + Tsyso.name
> FROM
> sys.tables Tsyst
> INNER JOIN sys.objects Tsyso
> ON Tsyst.object_id = Tsyso.parent_object_id
> WHERE (Tsyso.type = 'D')
>
No comments:
Post a Comment