12

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);
asked Dec 11, 2012 at 6:01
5
  • 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). Commented Dec 11, 2012 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. Commented Dec 11, 2012 at 7:32
  • 1
    Maybe it was designed by a former SAP consultant? Commented Dec 11, 2012 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. Commented Dec 11, 2012 at 15:13
  • 1
    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. Commented Dec 11, 2012 at 17:52

1 Answer 1

11

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

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.

Robert Harvey
201k55 gold badges470 silver badges682 bronze badges
answered Feb 16, 2013 at 14:26
1
  • 3
    Are you just speculating based on others' suggestion or do you have an actual source as to why Apple chose this convention? It's a pretty flimsy argument as it could have been prefixed with, for example, "ENTITY_". Or, if Apple has a need for internal, secret tables, those could be prefixed with Z and user tables can be named normally. The OP has asked WHY and I still don't see an actual reason. Commented Oct 19, 2015 at 18:08

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.