sp-msforeachtable

How to exclude tables from sp_msforeachtable

我是研究僧i 提交于 2019-11-30 17:20:16
I know that sp_msforeachtable allows to perform queries on all tables. I have 100 tables and I want to perform the same query on 97 tables. I'm using this query: EXEC sp_MSForEachTable "DELETE FROM ?" Is it possible to exclude certain tables? EXEC sp_MSforeachtable 'IF OBJECT_ID(''?'') NOT IN ( ISNULL(OBJECT_ID(''[dbo].[T1]''),0), ISNULL(OBJECT_ID(''[dbo].[T2]''),0) ) DELETE FROM ?' Alex Hinton Simplest syntax I came across to include or exclude schemas and tables: exec sp_MSforeachtable 'print ''?''', @whereand='and Schema_Id=Schema_id(''Value'') and o.Name like ''%Value%''' Hubbitus sp

SQL Server: How to make server check all its check constraints?

你离开我真会死。 提交于 2019-11-27 18:47:50
It seems that some scripts generated by Enterprise Manager* (or not, it doesn't matter) created check constraints WITH NOCHECK . Now when anyone modifies the table, SQL Server is stumbling across failed check constraints , and throwing errors. Can i make SQL go through all its check constraints, and check them? Running: sp_msforeachtable 'ALTER TABLE ? CHECK CONSTRAINT all' only enables previously disabled check constraints, it doesn't actually check them. Footnotes * SQL Server 2000 Nathan DBCC CHECKCONSTRAINTS WITH ALL_CONSTRAINTS won't actually make your constraints trusted. It will report

SQL Server sp_msforeachtable usage to select only those tables which meet some condition

偶尔善良 提交于 2019-11-26 16:33:12
I am trying to write this query to find all tables with specific column with some specific value. This is what I've done so far - EXEC sp_MSforeachtable @command1=' IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA=PARSENAME("?",2) AND TABLE_NAME=PARSENAME("?",1) AND COLUMN_NAME="EMP_CODE") BEGIN IF (SELECT COUNT(*) FROM ? WHERE EMP_CODE="HO081")>0 BEGIN SELECT * FROM ? WHERE EMP_CODE="HO081" END END ' I hope my intensions are clear, I just want to select only those tables where the column EMP_CODE is present and in those tables I want to select those rows where EMP_CODE=

SQL Server sp_msforeachtable usage to select only those tables which meet some condition

夙愿已清 提交于 2019-11-26 04:49:31
问题 I am trying to write this query to find all tables with specific column with some specific value. This is what I\'ve done so far - EXEC sp_MSforeachtable @command1=\' IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA=PARSENAME(\"?\",2) AND TABLE_NAME=PARSENAME(\"?\",1) AND COLUMN_NAME=\"EMP_CODE\") BEGIN IF (SELECT COUNT(*) FROM ? WHERE EMP_CODE=\"HO081\")>0 BEGIN SELECT * FROM ? WHERE EMP_CODE=\"HO081\" END END \' I hope my intensions are clear, I just want to select