Is it possible to get data of specific column on target system database?

I have the custom script that generates unique ID but it doesn't check the target system database which leads to duplication of ID.

Is there any way to check target system data to prevent duplication?