database model and sql code