Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I was looking at the sqlite table that Core Data generates and noticed that all table columns start with 'Z'. I realize this is an implementation detail, but I was curious as to why that's the case and if there was a design decision involved in this. Anyone happen to know or guess why?

Here's a sample schema output of Core Data sqlite database:

sqlite> .schema
CREATE TABLE ZPOST ( Z_PK INTEGER PRIMARY KEY, Z_ENT INTEGER, Z_OPT INTEGER, ZPOSTID INTEGER, ZUSER INTEGER, ZCREATEDAT TIMESTAMP, ZTEXT VARCHAR );
CREATE TABLE ZUSER ( Z_PK INTEGER PRIMARY KEY, Z_ENT INTEGER, Z_OPT INTEGER, ZUSERID INTEGER, ZAVATARIMAGEURLSTRING VARCHAR, ZUSERNAME VARCHAR );
CREATE TABLE Z_METADATA (Z_VERSION INTEGER PRIMARY KEY, Z_UUID VARCHAR(255), Z_PLIST BLOB);
CREATE TABLE Z_PRIMARYKEY (Z_ENT INTEGER PRIMARY KEY, Z_NAME VARCHAR, Z_SUPER INTEGER, Z_MAX INTEGER);
share|improve this question
    
I really have no idea about the reason in this specific case, but it is not uncommon for database tables serving a common purpose to be prefixed with a special prefix for easy reference and to avoid collision of other tables (e.g. user and zUser). –  Emmad Kareem Dec 11 '12 at 7:12
    
Possibly so that they're easy to spot. Apple is very clear that you should never edit Core Data tables with anything other than Core Data. It makes sense then to choose some unusual prefix for all Core Data tables so that it's easy to tell when you're looking at a Core Data table. –  Caleb Dec 11 '12 at 7:32
1  
Maybe it was designed by a former SAP consultant? –  Philipp Dec 11 '12 at 8:56
    
@Philipp may have a point, though I laughed at the initial suggestion. In SAP, you add Z to a custom table to ensure no collisions with SAP internal tables. The same may be going on here: CoreData adds a Z to the front of the tables created for your entities to ensure there are no table collisions with any of its internal stuff. –  jmstone Dec 11 '12 at 15:13
    
In my local dev database I prefix testing tables with a Z so they are alphabetically sorted to the bottom of the list. Makes it easier to see them together and delete them when I'm finished. –  mike30 Dec 11 '12 at 17:52
add comment

1 Answer

up vote 3 down vote accepted

It is the naming convention chosen to be used in Core Data SQLLite.

There are several reasons why it was chosen. One of the main reasons is Z is one of the least used letters of the alphabet so they surely felt by pre-fixing table names and entity names with Z they open more options for developers to name their own tables with fewer chances of stomping on someones naming conventions already.

Finally by using Z and all caps the Core Data tables are easier to spot and calls the entity objects out. In one comment in the question Mike mentioned that he also names his tables with a z so they sort the bottom. This might also have been a consideration.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.