SQL - Guess the output

Which statement(s) execute successfully or give error.

-- Statement 1 --
SELECT SYSOBJECTS.Name, SYSOBJECTS.Xtype, SYSOBJECTS.crdate, SYSOBJECTS.refdate
FROM SYSOBJECTS
GO

-- Statement 2 --
SELECT Name, Xtype, crdate, refdate
FROM SYSOBJECTS AS OBJ
GO

-- Statement 3 --
SELECT OBJ.Name, OBJ.Xtype, OBJ.crdate, OBJ.refdate
FROM SYSOBJECTS AS OBJ
GO

-- Statement 4 --
SELECT SYSOBJECTS.Name, SYSOBJECTS.Xtype, SYSOBJECTS.crdate, SYSOBJECTS.refdate
FROM SYSOBJECTS AS OBJ
GO

-- Statement 5 --
SELECT SYSOBJECTS.Name, OBJ.Xtype, OBJ.crdate, SYSOBJECTS.refdate
FROM SYSOBJECTS AS OBJ
GO
 
Answer: Statement 1 – Successful, Statement 2 – Successful, Statement 3 – Successful, Statement 4 – Error, Statement 5 – Error

Explanation: Using the table alias and the table name both in a single query in incorrect. If you are using table alias then you cannot use table name for reference in that query. You need to use the alias for reference.

No comments:

Post a Comment