+ 2

I don't understand where _ID is coming from in this join table code

WHERE costumer.ID=order.Customer_ID It's a sql, but I don't understand the underscore. What does it do, what's it for, why it's not also .I'd like the first one

1st Aug 2019, 2:27 AM
Amprex Production
4 Réponses
+ 4
It's just part of a field (column) name, you see, the `customer` table has a field named `ID` (commonly be a primary key). And the `order` table has a `Customer_ID` field, which is foreign key that references the `ID` field from the `customer` table. The underscore in the `Customer_ID` (in order table) field name is commonly used as a reminder, which table, and field this foreign key refers to. In this case, the `Customer_ID` field of `order` table references to table `Customer` and the refered field is `ID`; combined together the table and field name -> Customer_ID. It was merely a naming convention, in practice, we are free to name fields of tables as we see fit, preferably though, names are expected to be descriptive. P.S. I lost you on the second paragraph there, starting from "why it's not also ..." Hth, cmiiw
1st Aug 2019, 2:48 AM
Ipang
+ 3
You're welcome my friend : ) I'm afraid I won't encourage you to replace those underscore with a period, because the period is used as separator between an object and a member it owns; as we have seen in `order.Customer_ID` I'm afraid the use of period here may result in more of a confusion in reading probably : )
1st Aug 2019, 4:21 AM
Ipang
+ 2
Thank you for your time! I think I understand that there underscore (_) is not important, it could have been a period (.) If I changed order.Customer_ID to order.Customer.ID instead would it become invalid? I assume so
1st Aug 2019, 3:46 AM
Amprex Production
+ 1
It is the customer ID field from the order table 🤔
2nd Aug 2019, 3:53 AM
Sanjay Kamath
Sanjay Kamath - avatar