Why does Access 2016 reject the syntax [duplicate] - sql

This question already has an answer here:
MS Access: Syntax error in CREATE TABLE statement
(1 answer)
Closed 1 year ago.
I want to create a table with selected columns from an existing larger table The syntax below is what is recommended but ACCESS throws an error msg. What gives?
CREATE TABLE new_table_name AS
SELECT column1, column2
FROM existing_table_name
WHERE ....;

Every brand of SQL database can choose how complete its implementation of the SQL language is. MS Access in particular fails to support a lot of language features that are common in other brands of database.
You just have to verify the syntax you want to use is supported. You can do this by referring to the syntax documentation, for example: CREATE TABLE Statement. The syntax and description makes no mention of CREATE TABLE ... AS SELECT ...
But SELECT.INTO Statement shows that you can use the SELECT ... INTO newtable FROM ... form. The documentation says this will create newtable in the process.

MS Access doesn't have a "create table as select syntax". Instead, you can use the "select into" syntax:
SELECT column1, column2
INTO new_table_name
FROM existing_table_name
WHERE ...

Related

Trying to duplicate a table without data [duplicate]

This question already has answers here:
Create table (structure) from existing table
(17 answers)
Closed 3 years ago.
I have a table which I would like to duplicate without any data in it (Only the columns).
So I have 2 types of databases, Oracle and Sql Server.
I have constructed this:
CREATE TABLE TMPTABLE AS SELECT * FROM USERS WHERE 1 = 0
It works fine in the Oracle database, but in the Sql Server I get this error:
Error Number:156,State:1,Class:15 Incorrect syntax near the keyword 'SELECT'.
Sql Server version: 14.0.1000.169.
try this
CREATE TABLE newtable SELECT * FROM oldtable
Without AS

Select into temp table in PostgreSQL? [duplicate]

This question already has answers here:
Creating temporary tables in SQL
(2 answers)
Closed 7 years ago.
How to create temporary table using select into in PostgreSQL. For example in SQL Select * into temp_tab from source_tab;
You can try to use Create Table As command like this:
CREATE TEMP TABLE mytable AS
SELECT * from source_tab;
From the docs:
This command is functionally similar to SELECT INTO, but it is preferred since it is less likely to be confused with other uses of
the SELECT INTO syntax. Furthermore, CREATE TABLE AS offers a superset
of the functionality offered by SELECT INTO.
The CREATE TABLE AS command allows the user to explicitly specify
whether OIDs should be included. If the presence of OIDs is not
explicitly specified, the default_with_oids configuration variable is
used.

Oracle SQL Developer - Display SELECT output in Query Results window when using PLSQL [duplicate]

This question already has answers here:
How to export query result to csv in Oracle SQL Developer?
(6 answers)
Closed 8 years ago.
I use an Oracle SQL Developer script to do a SELECT, displaying results in Query Results window. I then copy/paste the results into an Excel template for reporting.
I would like to replace the script with a PLSQL block, to allow looping etc. The problem is that simple SELECT FROM (without INTO) doesn't seem to work in PLSQL.
Is there any way to use PLSQL to display the results of a select in a window which I can copy/paste from?
Note: I am disallowed from using EXPORT to create text files directly, which would be much better than copy/paste. There is also a standard Oracle package that does output to a file directly from PLSQL, but I am disallowed from using it, too.
This post was marked as a duplicate of another post, one which asked how to get output from a SELECT that was NOT in a PL/SQL block. I do know how to do that and in fact it's what I am doing currently, as I mentioned in the OP. As I said, SELECT without INTO fails in PL/SQL.
You can create a temporary table:
CREATE GLOBAL TEMPORARY TABLE table_name (
( column1 datatype null/not null,
column2 datatype null/not null,
...
) ON COMMIT DELETE ROWS;
Then through each loop, you can insert your data in it:
INSERT INTO table_name
(SELECT statement);
Finally you can use select statement on temporary table to read data:
SELECT * FROM table_name
and then drop table:
drop table table_name;

I want to create a new table from a SQL select statement?

I want to be able to create new tables based on any SQL select statement. I have tried the following which I got the format from another question and it does not work (there are similar questions but not one that I found actually works). I keep getting an error on the SQL statement.
Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'AS'.
This is the CREATE TABLE statement:
CREATE TABLE MyNewTable
AS
SELECT *
FROM dbo.Bat
This will copy the entire table including rows
SELECT *
INTO newTableName
FROM dbo.Bat
Add WHERE 1 = 0 to copy just the table structure
If it is SQL Server (the dbo schema, default in SQL Server indicates it is SQL Server), you can do following.
select * into MyNewTable from dbo.Bat;
The SELECT INTO statement does not copy your table constraints.
You statement is a valid Oracle and MySQL statement though.
CREATE TABLE ... AS SELECT is simple (by deliberately ignoring for example the concepts of storage)
To create a table with all its lines
code:
CREATE TABLE XX AS SELECT * FROM YY ;
the result of command in mysql

Oracle and Sybase compatibility for create table new_table as

I am trying to write an SQL query which needs to be compatible on both a Sybase and Oracle database. The query looks like the following :
SELECT *
INTO new_table
FROM other_table
This query is working great on a Sybase database but not on an Oracle one. I found the equivalent for Oracle :
CREATE table new_table AS
SELECT *
FROM other_table
Is there a way to write a third query that would do the same and that can be executed on a Sybase and on an Oracle database?
As you found, Oracle supports INTO but doesn't use it like Sybase/SQL Server do. Likewise, Sybase doesn't support Oracle's extension of the CREATE TABLE syntax.
The most reliable means of creating a table & importing data between the systems is to use two statements:
CREATE TABLE new_table (
...columns...
)
INSERT INTO new_table
SELECT *
FROM OLD_TABLE
Even then, syntax is different because Oracle requires each statement to be delimited by a semi-colon when TSQL doesn't.
Creating a table & importing all the data from another table is a red flag to me - This is not something you'd do in a stored procedure for a production system. TSQL and PLSQL are very different, so I'd expect separate scripts for DML changes.
There is no query that would do what you want. These environments are very different.
It is possible.
SELECT * INTO new_table FROM existing_table;
Thanks