c5374e4c9019d2b22513f53867edd3f1802a8630 kent Fri Apr 19 13:17:42 2013 -0700 Adding docs and test cases for index and autoincrement feature. diff --git src/hg/autoSql/autoSql.doc src/hg/autoSql/autoSql.doc index b5638d5..43109d6 100644 --- src/hg/autoSql/autoSql.doc +++ src/hg/autoSql/autoSql.doc @@ -236,48 +236,82 @@ { symTestCProg = 0x0001, symTestJavaProg = 0x0002, symTestPythonProg = 0x0004, symTestAwkProg = 0x0008, }; struct symTest /* test of enum and set symbolic columns */ { struct symTest *next; /* Next in singly linked list. */ int id; /* unique id */ enum symTestSex sex; /* enumerated column */ unsigned skills; /* set column */ }; +INDEXES and AUTOINCREMENT + +You can explicitly add indexes to fields in AutoSQL. If you don't explicitly add an index +it will assume the first field is the primary key and index it as such. To add an index +include one of the keywords 'primary' (for primary key) 'unique' (for an index on a field +where all values are unique) or 'index' (for fields that may contain duplicate values). It is +possible to just index the first part of a field by including the number of characters. + +An integer (signed or unsigned, small or large) can be make an auto-increment column, where +the database automatically assigns an incrementing numerical value to it, by including the +'auto' key word after the index if any. + +Some examples with indexes and autoincrement: + +table addressBook +"A simple address book" + ( + uint id primary auto; "Autoincrementing primary key for this record." + string name unique; "Name - first or last or both, we don't care, except it must be unique" + lstring address; "Street address" + string city index[12]; "City - indexing just first 12 character" + uint zipCode index; "A zip code is always positive, so can be unsigned" + char[2] state index; "Just store the abbreviation for the state" + ) + + GRAMMER The grammer for AutoSQL is: declarationList: declaration declarationList declaration declaration: declareType declareName comment '(' fieldList ')' declareType: 'simple' 'object' 'table' declareName: name + name indexType + name 'auto' + name indexType 'auto' + +indexType: + 'primary' + 'index' + 'unique' comment: quotedString fieldList: field fieldList field field: fieldType fieldName ';' comment fieldType '[' fieldSize ']' name ';' comment fieldType '(' fieldValues ')' name ';' comment fieldName: name