0

I'm trying to figure out the correct name for table labeling.

SELECT var1, var2 FROM myTable TableRef

The label I'm referring to is the variable TableRef, which can be referenced from a WHERE clause like follows:

WHERE TableRef.var1 = 'someValue'
Jack Zach Tibbles
  • 800
  • 1
  • 11
  • 27
  • 1
    no general naming convention exists, it depends particularly on company standards – Nadeem_MK Sep 25 '14 at 11:30
  • 2
    The specific term is "table alias". This is to distinguish it from a "column alias". When you use it with a column (`TableRef.var1`) you are *qualifying* the column name. – Gordon Linoff Sep 25 '14 at 11:36
  • Your statement about referencing the label in the where clause is not correct in the example you gave. About that delete statement, it's probably possible but it's always a good idea to do a similar select query first so that you can verify that the rows about to be deleted are the ones you want deleted. – Dan Bracuk Sep 25 '14 at 11:41
  • Our company prefixes our tables with "tbl" and our views with "vw". I'm not saying its the right thing to do but it does help to know what you are selecting – Bobby Sep 25 '14 at 11:58
  • 2
    @Bobby why does it matter if you're selecting from a table or a view? If you need to differentiate, I would say put the prefix on the view, but there is no good reason to prefix every table with `tbl`. Do you also put `usp_` in front of every stored procedure? Why? What are you going to confuse a stored procedure with? – Aaron Bertrand Sep 25 '14 at 13:21
  • 1
    I recommend using `FROM dbo.myTable AS TableRef`. (1) [always use the schema prefix](https://sqlblog.org/blogs/aaron_bertrand/archive/2009/10/11/bad-habits-to-kick-avoiding-the-schema-prefix.aspx) (2) the AS makes the intent clearer and makes it unambiguous that it isn't a hint of some kind. – Aaron Bertrand Sep 25 '14 at 13:22
  • @AaronBertrand Are you mad? We use "sp" not "usp_". I'm just following our standards – Bobby Sep 25 '14 at 13:42
  • @Bobby http://sqlperformance.com/2012/10/t-sql-queries/sp_prefix – Aaron Bertrand Sep 25 '14 at 13:43
  • @AaronBertrand Thanks, I never knew any of that – Bobby Sep 25 '14 at 13:45

1 Answers1

1

As @Yosi pointed out. The term I was looking for was table alias.

Jack Zach Tibbles
  • 800
  • 1
  • 11
  • 27