How to name a SQL query?

0

Issue

My professor is asking for me to include a query name for each and every query that is involved with this homework. I’m assuming he’s referring to an alias, so I’ve used this code successfully with some questions:

SELECT COUNT(CustomerID) AS Problem1
FROM Customers;

However, I can’t us AS when creating tables or deleting columns like this (without an error).

CREATE TABLE TestDB AS Problem6
(
SuggestionID Char(5) NOT NULL PRIMARY KEY,
Suggestion VarChar(100) NOT NULL,
SugContact Char(30) NOT NULL,
SugPhone Char(10),
SugDate Date NOT NULL,
SugPriority INT
)

OR when using INSERT INTO. So my question is this: how do I name a specific query, specifically when creating a database like the above or when deleting a column.

Solution

It is not possible to name a query as such – you could put it into a stored procedure or alternatively – and more likely, he’ll just want you to label the query with a comment like so:

-- Question 1
CREATE TABLE TestDB( ...

Answered By – Mikey

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More