HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

Creating a function for a simple select statement?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
simplestatementcreatingfunctionforselect

Problem

I'm writing an application and I'll be running the following query:

SELECT Job_name,EMP,Lastname,FirstName from employe E
inner join JOBS F ON F.CODE_JOB=  E.CODE_JOB
inner join EMPS S ON S.Code_str = E.CODE_STR
where USER_ID = X


Does it make sense to actually make a function for it and send the USER_ID as a parameter or should I just run the query in the application? I'm just looking to know what are the best practices here.

Solution

You could write an inline table valued function, or use a view to encapsulate this code, but it would depend on what you hope to get out of it.

There's no performance gain by doing so. It can make the application query simpler, or obfuscate table names, but that's about it.

Obfuscating table names may provide an additional, though minimal layer of security. Any escalation of privileges could result in someone seeing the view definition and exposing the table names anyway.

Context

StackExchange Database Administrators Q#211780, answer score: 4

Revisions (0)

No revisions yet.