4

I am trying to CREATE VIEW in access in SQL view but I am getting a syntax error for CREATE TABLE which is highlighting the word VIEW. This is in Access 2016 via Office 365 (latest update as of 2/11/2019). The SELECT statement works by itself, but the CREATE VIEW command isn't. My book (Concepts of Database Management) is designed for use specifically alongside Access. My code is as such:

CREATE VIEW TopLevelCust AS
SELECT CustomerNum, CustomerName, Street, Balance, CreditLimit
FROM Customer
WHERE CreditLimit>=10000
;
11
  • Hi Christopher, welcome to StackOverflow. In a Microsoft Access database there are no "views", just tables, indexes and queries (and some other object types like forms and reports that can't be managed using a SQL statements). Are you sure that your statement should be executed in a Microsoft Access database? Commented Feb 11, 2019 at 21:30
  • @WolfgangKais Access does support views, as well as the CREATE VIEW DDL Statement when used with an Access DB Engine. Commented Feb 11, 2019 at 21:32
  • 1
    Also, try turning on ANSI-92 SQL in the database options Commented Feb 11, 2019 at 21:39
  • 1
    I see that option under Object Designers but it wont let me apply to the current databse, only select "Default for new databases" Commented Feb 11, 2019 at 21:43
  • 1
    I just tried that out: Checked the option (for new databases), created a new database, and indeed, in that database, a CREATE VIEW can be executed. It creates a query. :-) Commented Feb 11, 2019 at 21:50

2 Answers 2

5

As already stated in Lynn's answer, if you want to execute this query, you can do that after turning on SQL server compatible syntax.

However, you can also execute the query using an OLEDB connection to the Access database.

You can even do this using VBA and the already preset CurrentProject.Connection object:

CurrentProject.Connection.Execute "CREATE VIEW Query1 AS SELECT 1"

Without turning on SQL server compatible syntax, DDL statements executed from Access itself are fairly limited (for example, you can also not use the Decimal data type). But these DDL statements are not really meant to be executed from Access itself, VBA provides way better tools to create queries (that also allows creating pass-through queries, for example).

Sign up to request clarification or add additional context in comments.

Comments

4

According to the asker and other users, enabling ANSI-92 SQL in the database options will allow you to execute the DDL statement CREATE VIEW.

File > Options > Object Designers > Query Design.

According to Wolfgang, under the hood, this actually creates a query.

<SoapBox>

It surprises me that your text reference requests you to execute statements that aren't enabled by default in Access, especially without a special note screaming at you that you need to enable a special option before database creation. ¯\_(ツ)_/¯

</SoapBox>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.