sql script for computing space to allocate