r/SQLServer • u/Reasonable-Job4205 • Aug 10 '26
Discussion How much prefix adding do you do to your objects in SSMS? Is it still important?
I am naming all my stored procedures as "spActualSPName". I got into this habit because of working with a SQL database that used MS Access as the front end, so it was helpful to know that the thing I was looking at in VBA was an SP. Is prefixing still needed? Do you do this?
9
Upvotes
8
u/alinroc 4 Aug 10 '26
Leave Hungarian Notation in the 20th century. SQL Server (and SSMS) keeps objects organized for you automatically.
20
u/oldmanmagic54 Aug 10 '26
I prefix Views and Stores Procedures so that when Iām hunting for something by name I at least know which broad category to look in
18
u/IanYates82 Aug 10 '26
No, haven't done it in a long time, and never really did anyway. I then recently worked in a database that had tbl prefixes, which was annoying, but even more tedious was that almost every column had a "fld" prefix... That was pure noise and, even in the old "prefix everything" mentality, gave zero benefit.
13
u/BrupieD Aug 10 '26
I find this kind of Hungarian notation annoying and unhelpful. SQL Server has system stored procedures prefixed with "sp_" and I don't want to mix mine with those. If there are 100 stored procedures that I have to scroll through and look for the characters that follow this prefix it really isn't helping me. I had a colleague who prefixed all his tables with "tbl." It sucked.
8
u/smailliwniloc Aug 10 '26
No prefixes anywhere
4
u/SQLGene Aug 10 '26
I don't find it particularly useful. The main exception is vw_ so I know if that is being queried is a view or table, since that's not easily discernable from syntax alone.
3
u/bobchin_c Aug 10 '26
We name our stored procs as usp_<SProcName>
3
u/JTBub Aug 11 '26
Prefer everything prefixed except field names. Nothing more fun than getting an error in a ticket theres an error in "CalcSum" and figuring out if it's front end or back end and if it's a table, synonym, function, sp etc. Other people will be called on to fix your code. Be kind to them.
3
u/DavidKleeGeek āŖ āŖMicrosoft MVP āŖ āŖ Aug 11 '26
I'd say it's more personal preference than anything at this point, as long as it's not specifically prefixed "sp_". SQL Server will assume the procedure is in the master database, and will first look there before looking in your specific database. IMHO it's more preference for you, your development and management style, and any historical precedence set by anyone working on your database(s) before you.
But - the comment below about using schemas - use them for logical grouping. It does make sense!
7
u/rhbcub Aug 11 '26
I don't.
Use schemas for logical separation.
If you can't recognize a stored procedure in context, step away from the keyboard :D
5
u/woo545 Aug 10 '26
usp_ for sprocs. vw_ for views ufn_ for functions. Nothing for tables
2
u/jwk6 Aug 11 '26
usp_ for user stored procedures (avoid sp_ because only system sprocs should use it) vw_ for views udf_ for user defined functions pk_ and ix_ for indexes
There are a few others.
Also prefer prefixing with the entity name and following that with the purpose or function. I.e. usp_SalesOrderLineItem_Merge so that object names sort nicely.
Otherwise I despise underscores, and prefer everything else in PascalCase /TitleCase.
I think you do this purely for the clarity and readability of your T-SQL code these days, but I also get that it may not considered "modern" to some people. Or considered Department of Redundancy Departmentā¢ļø š¤£
But please for the love of E. F. Codd, never tibble your tables!! (with tbl or tbl_ ā ļø)
2
u/dadepretto Aug 11 '26
I donāt use Hungarian Notation. I always use schemas, quote all names, and use semicolon at the end of a statement.
execute [App].[Order_Create] ā¦;
select [Id], [CustomerId], [Date]
from [Data].[Order];
declare @stmt = āā¦ā;
execute [sys].[sp_executesql] @stmt = @stmt;
2
u/AtmosfericGothic Aug 11 '26
"sp" is used for system stored procedures.
We use "usp_" as user stored procedures, "vw_" for views, and no prefix for tables.
We also use prefix-style naming to group objects inside schemas. For example, in the cube schema:
cube.vw_fact_sale
cube.vw_fact_payment
cube.vw_dim_store
cube.vw_dim_item
And the words in object names should go from more general to more specific.
rep.agent
rep.agent_store
rep.agent_store_calendar
This way related objects are grouped together naturally in the SSMS object list.
I call it poor man's OOP. :)
2
u/CanProfessional766 Aug 12 '26
I donāt bother with
spprefixes. SSMS already tells you itās a stored procedure, and names likeGetCustomerOrdersare just easier to read. That said if your team already uses prefixes consistently, Iād stick with the convention2
u/jay_butler Aug 12 '26
Access naming conventions are awful. I donāt prefix anything. I generally name stored proc in the verb-noun convention. So, things like getCustomer or createOrder.
1
u/mkt853 Aug 10 '26
It's useful if you want to have a table with a view that sits on top with the same name. For other objects I find I don't run into naming conflicts as often.
1
u/kapilverma123 Aug 11 '26
I still use prefixes to some extent, mainly because they make it easier to identify object types at a glance in a large database. That said, I avoid
sp_specifically for stored procedures since SQL Server reserves that convention for system procedures. In an existing project, though, Iād prioritize consistency over changing everything.1
u/Riga_M0rt1z Aug 11 '26
for tables, its almost a must, when joins have tables with similar / same names, you want to know where table they come from, so a prefix helps audit your ELT processes
1
u/PaulPhxAz 1 Aug 11 '26
No prefix, no need. Domain_TopicOrTable_Action
Like Accounting_Reconciliation_EndOfDay
Never put your verb first, or you'll see everything related to "Get" or "Update" next to each other, which is less helpful than the domain and topic.
1
u/BornSQL Aug 16 '26
No.
1
u/ithinkilikerunning Aug 11 '26
We prefix stored procedures by what they do. SEL_ for basic stored procedures that return data. DEL_ for deletes. INS_ for inserts. UPD_ for updates.