perfect database operation function