What's the Purpose of SQL Keyword "As"

What's the purpose of SQL keyword AS?

There is no difference between both statements above. AS is just a more explicit way of mentioning the alias

What is the point using AS keyword in SQL when aliasing can be done without it?

I think the reason is simple. Consider code such as the following:

select a, b, c, d
. . .

It is very easy to occasionally skip the comma:

select a b, c, d

If you don't use as then this looks like correct code and it can be difficult to figure out. If you always use as for column aliases, then you know it is incorrect.

How to know where AS keyword should be used?

Main uses:

  • Aliases for tables and columns
  • Between CREATE and definition
  • CAST AS newtype

Examples

SELECT
foo AS tom,
foo + bar AS dick,
CAST(bar AS varchar(50)) AS harry
FROM
fizz AS f

CREATE VIEW/PROC/FUNCTION etc
AS
... proc or view of udf etc definition
GO

T-SQL: What does the AS keyword mean in this context?

The AS here is part of the required syntax of the CREATE PROCEDURE statement.

(See Microsoft Docs.)

As such it is pure syntax, it has no real "meaning" on its own.

Is the 'as' keyword required in Oracle to define an alias?

According to the select_list Oracle select documentation the AS is optional.

As a personal note I think it is easier to read with the AS

USING Keyword vs ON clause - MYSQL

The USING clause is something we don't need to mention in the JOIN condition when we are retrieving data from multiple tables. When we use a USING clause, that particular column name should be present in both tables, and the SELECT query will automatically join those tables using the given column name in the USING clause.

For example, if there are two common column names in the table, then mention the desired common column name in the USING clause.

USING is also used while executing Dynamic SQL, like so:

EXECUTE IMMEDIATE 'DELETE FROM dept WHERE deptno = :num'
USING dept_id;
  • The USING clause: This allows you to specify the join key by name.

  • The ON clause: This syntax allows you to specify the column names for join keys in both tables.

The USING clause

The USING clause is used if several columns share the same name but you don’t want to join using all of these common columns. The columns listed in the USING clause can’t have any qualifiers in the statement, including the WHERE clause.

The ON clause

The ON clause is used to join tables where the column names don’t match in both tables. The join conditions are removed from the filter conditions in the WHERE clause.

What is the difference between a keyword and a clause in SQL?

Making it clear by an example

SELECT  col1
,col2
,col3
FROM yourTable1 AS t1
INNER JOIN yourTable2 AS t2 ON t1.Id = t2.Id
WHERE col1 = 'aaaa'
AND col2 = 'bbbb'
ORDER BY col1

This is a SELECT statement or query

FROM yourTable1 AS t1 INNER JOIN yourTable2 ==> FROM clause

ON t1.Id = t2.Id ==> ON clause

WHERE col1 = 'aaaa' AND col2 = 'bbbb' ==> WHERE clause

ORDER BY col1 ==> ORDER BY clause

SELECT, FROM, WHERE, ON, AS, AND, ORDER BY are all keywords

What is the purpose of no Keyword in Sql Server 2012?

It's only reserved just-in-case some engine might use it, to ensure compatibility with drivers that support the core SQL grammar:

"The following words are reserved for use in ODBC function calls. These words do not constrain the minimum SQL grammar; however, to ensure compatibility with drivers that support the core SQL grammar, applications should avoid using these keywords."

https://learn.microsoft.com/en-us/sql/t-sql/language-elements/reserved-keywords-transact-sql?view=sql-server-2017&viewFallbackFrom=sql-server-2012

It's not only reserved by Microsoft.

https://firebirdsql.org/en/iso-9075-sql-standard-keywords-reserved-words/

Why does 'event' appear as a keyword in SQL?

It is a special keyword for SQL server. As you can see;

CREATE EVENT NOTIFICATION

CREATE EVENT SESSION

So, I suggest you to don't use this kind of keywords to don't get confusion.

Also, still if you want to stay with this keyword, you can provide the query with [] like omr.[event]



Related Topics



Leave a reply



Submit