i want to know both from code and SQl for real time application.