Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Advice needed on Sql Select
Message
 
 
To
25/04/2014 17:26:33
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:
01599103
Views:
59
>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.

-----------------------------------
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.
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform