gpt4 book ai didi

t-sql - sp_msforeachtable 没有给我正确的结果

转载 作者:行者123 更新时间:2023-12-01 15:39:22 26 4
gpt4 key购买 nike

我想使用 sp_msforeachtable 对数据库中的某些表执行一些操作。我使用 IF 语句来过滤表。但它没有给我正确的答案。如以下脚本所示,我使用 AdventureWorks 进行测试。我想对除 Person.AddressPerson.ContactPerson.CountryRegion 之外的每个表进行一些工作。正如您所看到的,这些表仍然包含在结果中。为什么?谁能帮助我解决我的问题?非常感谢。

sp_msforeachtable '
IF ''?'' <> ''Person.Address'' AND ''?'' <> ''Person.Contact'' AND ''?'' <> ''Person.CountryRegion''
BEGIN
PRINT ''?''
END
';

结果是:

[Sales].[Store]
[Production].[ProductPhoto]
[Production].[ProductProductPhoto]
[Sales].[StoreContact]
[Person].[Address] <------------------------------
[Production].[ProductReview]
[Production].[TransactionHistory]
[Person].[AddressType]
[Production].[ProductSubcategory]
[dbo].[AWBuildVersion]
[Production].[TransactionHistoryArchive]
[Purchasing].[ProductVendor]
[Production].[BillOfMaterials]
[Production].[UnitMeasure]
[Purchasing].[Vendor]
[Purchasing].[PurchaseOrderDetail]
[Person].[Contact] <------------------------------
[Purchasing].[VendorAddress]
[Purchasing].[VendorContact]
[Purchasing].[PurchaseOrderHeader]
[Sales].[ContactCreditCard]
[Production].[WorkOrder]
[Person].[ContactType]
[Sales].[CountryRegionCurrency]
[Production].[WorkOrderRouting]
[Person].[CountryRegion] <------------------------------
[Sales].[CreditCard]
[Production].[Culture]
[Sales].[Currency]
[Sales].[SalesOrderDetail]
[Sales].[CurrencyRate]
[Sales].[Customer]
[Sales].[SalesOrderHeader]
[Sales].[CustomerAddress]
[HumanResources].[Department]
[Production].[Document]
[HumanResources].[Employee]
[Sales].[SalesOrderHeaderSalesReason]
[Sales].[SalesPerson]
[HumanResources].[EmployeeAddress]
[HumanResources].[EmployeeDepartmentHistory]
[HumanResources].[EmployeePayHistory]
[Sales].[SalesPersonQuotaHistory]
[Production].[Illustration]
[Sales].[SalesReason]
[Sales].[Individual]
[Sales].[SalesTaxRate]
[HumanResources].[JobCandidate]
[Production].[Location]
[Sales].[SalesTerritory]
[Production].[Product]
[Sales].[SalesTerritoryHistory]
[Production].[ScrapReason]
[HumanResources].[Shift]
[Production].[ProductCategory]
[Purchasing].[ShipMethod]
[Production].[ProductCostHistory]
[Production].[ProductDescription]
[Sales].[ShoppingCartItem]
[Production].[ProductDocument]
[Production].[ProductInventory]
[Sales].[SpecialOffer]
[Production].[ProductListPriceHistory]
[Sales].[SpecialOfferProduct]
[Production].[ProductModel]
[Person].[StateProvince]
[Production].[ProductModelIllustration]
[dbo].[DatabaseLog]
[Production].[ProductModelProductDescriptionCulture]
[dbo].[ErrorLog]

最佳答案

您尝试过添加括号吗?

sp_msforeachtable '
IF ''?'' <> ''[Person].[Address]'' AND ''?'' <> ''[Person].[Contact]'' AND ''?'' <> ''[Person].[CountryRegion]''
BEGIN
PRINT ''?''
END
';

关于t-sql - sp_msforeachtable 没有给我正确的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3150151/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com