首页 文章

如果列值id与另一个表中的ID描述匹配,则在指定列中插入数据(规范化形式)

提问于
浏览
0

为了做到这一点(在 Headers 描述中),显然它已经是一个规范化的数据库,因此肯定会使用内部联接类型的检查 .

假设我们有一个customer表和一个给定的customer_ID作为主键以及描述名字姓氏等,并且在另一个表(Customer_Sales_History)Customer_ID列上也是为了使其可以在查询中进行搜索 .

更新:我的努力是我需要在特定列中添加以XML(Soap响应)格式获取的特定数据,但通过Customer_Name和Customer_Lastname检查附加到特定的Customer_ID .

如果Customer_Name =“John”且Customer_Lastname =“Martin”,则使用值填充salescode productquantity和productdescription

卷很大(数千行),因此可能必须将sql填充为来自另一个表的插入,这对于那种类型的slqing卷来说是相当新的 .

Customer Table
Customer_ID | Customer_Name | Customer_Lastname 
1           |  John         | Martin
2           |  Jack         | White
3           |  Don          | Carrera

     Customer_Sales_History Table

Customer_ID | Sales_Code | ProductQuantity | ProductDescription
2           |     X      |        X        |         X

为了将给定数据插入Customer_Sales_History表,并将Customer_ID 2作为给定目标,我必须匹配Customer_Name = Jack和Customer_Lastname = White的行,并填充Sales_Code Product_Quantity和产品描述 .

2 回答

  • 1
    Update ch
    set ch.sales_code = ...,
        ch. ProductQuantity =...,
    from  Customer_Sales_History ch join Customer c on ch. Customer_ID= c.Customer_ID
    where ch.Customer_ID=2
    
  • 0

    如果您已将customer表中的customer_ID声明为主键,并将Customer_Sales_History表中的customer_ID声明为外键,则它将自动执行检查部分 . 那么,为什么你需要明确地检查customer_id?

相关问题