liveBook · Manning

Object prefix

As explained in 100 SQL Server Mistakes and How to Avoid Them

An object prefix is a naming convention that adds a type-indicating string to the beginning of a database object name.

An object prefix adds a type-indicating string to a database object name, such as tbl_, sp_, fn_, or v_. It may seem to make object types immediately recognizable, but repeated prefixes slow visual scanning for developers, business intelligence developers, and administrators. section 2.3

Mistake: naming every object by type

In the MagicChoc SalesDB, tbl_customers and v_customers identify a table and view through their names. However, SQL Server already separates them in Object Explorer, and sys.objects returns their type descriptions. The prefix adds parsing work without improving identification. section 2.3

Prefer these checks before adopting prefixes:

  • Use Object Explorer categories to distinguish tables, views, and other objects. section 2.3
  • Query sys.objects when code needs an object's type. section 2.3
  • Rename existing objects carefully when removing prefixes; dependent views and procedures require deliberate handling. section 2.3
Listing 2.7 Returning the customers objects
SELECT
      name
    , type_desc
FROM sys.objects
WHERE name LIKE '%customers%' ;

Inspect matching object names and their SQL Server types with a sys.objects query. section 2.3

How 100 SQL Server Mistakes and How to Avoid Them covers it

How deep it goes
Explains the convention, its scanning cost, alternative type inspection, and prefix-removal commands.
Examples
Uses MagicChoc SalesDB names, Object Explorer, a sys.objects query, and prefix-removal T-SQL.
What it assumes
Assumes familiarity with database objects and SQL Server tooling while teaching the naming tradeoff from concrete examples.
What you can do after
Evaluate object types through SQL Server tools and avoid prefixes that hinder visual scanning.
How it connects
Connects naming conventions with SQL Server object types, Object Explorer, sys.objects, tables, views, and stored procedures.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of 100 SQL Server Mistakes and How to Avoid Them. The section links point to the parts of the book it draws on.