The following is dapted from letters from Tara Watson and Caroline Hoxby. The district code is only unique with a state. NCES uses a combination of the state code and the district code to identify districts across states. Multiple the fips code by 100000 and add the school district code, that generates the NCES code that is unique for each district.
Because the SDDB depends on adminstrators' self reports, differences in districts' student accounting practices do make themselves felt.
The states seem to be ordered alphabetically by 2-digit abbreviation as far as I can tell. (It starts with 2, which is Alaska, then goes to 1 which is Alabama.)
For each state, the file first lists the state total and then county totals for each county in the state. The disype is "9". (The county id for the state totals is 0.) There are no school district IDs or enrollment info. These observations are not necessary for someone just interested in school districts.
Then, the file list the school district summaries for each school district in the state. The disttype is 1 for a unified (elementary and high school) district, 2 for just elementary, and 3 for just high school, 4 for just junior high, also 6 and 8 are used occasionally. There are district identifiers up to 5 digits. I believe these should be combined with the 2-digit FIPS codes to make a 7-digit NCES number. The school district information has no county identifiers. An outside source would have to be used to match school districts to counties. The match would be imperfect when school districts cross county lines.
There are 16 AEA districts with state of 0. I am not sure what this means (maybe BIA schools?). Hawaii (state 15) has no enrollment data, although I was under the impression it was really all one school disrtict anyway.