Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Advice needed on Sql Select
Message
From
28/04/2014 17:46:12
Mike Yearwood
Toronto, Ontario, Canada
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows 7
Network:
Windows 2008 Server
Database:
Visual FoxPro
Application:
Desktop
Miscellaneous
Thread ID:
01599095
Message ID:
01599194
Views:
112
>>Whether the table is plural or singular is merely personal preference. A phone book is singular. It contains nameS, addressES and phone numberS of people or persons. What affects readability far more is avoiding arbitrary aliases such as t1 and t2 and instead using more descriptive aliases such as BeginDef and EndDef
>>
>>
select ;
>>  Employee.EmployeeId, ;
>>  Employee.BeginTime, ;
>>  BeginDef.DescTime  as BeginDef, ;
>>  Employee.EndTime, ;
>>  EndDef.DescTime as EndDef ;
>>from Employee ;
>>LEFT JOIN TimeDef BeginDef on Employee.BeginTime = BeginDef.IdTime
>>LEFT JOIN TimeDef EndDef on Employee.EndTime = EndDef.IdTime
>>
>>You can now see that BeginTime has a corresponding BeginDef and EndTime has a corresponding EndDef. You can infer that BeginDef and EndDef are aliases of TimeDef and you won't be pausing to wonder if t1 or t2 was the start or end alias. Such things really have a beneficial impact in more complex queries.
>>
>>LEFT JOINs also show employee records with missing data or records that preceded the eventual addition of TimeDef as a new feature.
>
>LEFT JOIN may be correct for the EndTime assuming that EndTime can be open (e.g. NULL). If the BeginTime is defined as NOT NULL in the table and it's a foreign key to the TimeDef table, then it should be an INNER JOIN.

In theory it should be an inner join. However, in practice, if the TimeDef table was added as a new feature, and there are 10 million Employees and only 1 million of them have a non-null value because we haven't updated all 10 million records yet, then it will have to be a LEFT JOIN until not even 1 employee remains without that value. You would not be able to set the column to NOT NULL, and therefore you would not be able to use the INNER JOIN. You will get ambushed when 9 million employees don't get a pay check because you INNER JOINed. You must know the theory, but you better be ready to compromise the theory for practical purposes.

>
>-----------------------------------
>As for the table names - it is not exactly a personal preference. I think there should be some good standards in naming database objects. I do know many high regarded Database Experts who favor plural for table names.

Makes no difference to SQL implementations. It's only a convenience for people - that makes it personal. One group of "experts" prefers it one way, while the other group prefers it another way. That makes it a preference.
Previous
Reply
Map
View

Click here to load this message in the networking platform