Question

When i write:

if not exists (select * from sys_maxkey)

is better,or

if not exists (select id from sys_maxkey)

is better when the table sys_maxkey variable.

or it has no difference?I have found internet and analyse exists and in but not pay attention to this special point.

Thank you!

Was it helpful?

Solution

I would suggest to use only 1 like this. This would be the best. As exists only checks whether there is any entry in your table.

if not exists (select 1 from sys_maxkey)

Although if you want to compare between the above two mentioned in your question then

if not exists (select id from sys_maxkey)

would be better provided that id is the primary key. You dont have to check all the columns by using * just for checking whether there exists a value in your table.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top