build database sql