There are two ways to reference a table or field name with dashes, hyphens or reserved words:
1) Use double quotes on table names. For example:
SELECT * FROM pub."Order"
Order is a SQL Reserved Word and needs to be in quotes.
The second statement inserts a new record into the Customer table and inserts the value 1 into the Number field. The word Number is also a SQL Reserved Word that must be in quotes. For example:
INSERT INTO pub.customer ("Number") VALUES (1)
The third statement selects all records from the order-line table. SQL-92 does not allow dashes in the field or table name and hence it must be enclosed in the double quotes. For example:
SELECT * FROM pub."order-line"
2) Create a view to reflect the same table with all the fields selected. For Date Fields enclose them in single quotes. For example:
SELECT * FROM pub.invoice WHERE "invoice-date" = '1993-02-08'
3) The same is true for creating a VIEW.
Assume the addition of the field Date-Of-Death to records in the EMPLOYEE table of the sports2000 database.
Further assume the addition of an employee named Donald Duck, EmpNum 9876543 who died 12/21/2018.
Further assume the desire to create a VIEW named Dead-Emp (show employees that have died).
To create a VIEW of employees that died on 12/21/2018, the following is required to successfully create the VIEW:
CREATE VIEW "Dead-Emp" AS SELECT EmpNum, LastName FROM Pub.EMPLOYEE WHERE "Date-Of-Death" = '12/21/2018';
To use the VIEW, the following is required:
SELECT * FROM "Dead-Emp";
Using sqlexplorer, this results in the following: