Execution from the statement select * into return error - sql

Can somebody help me?
I am try execute the command below in Oracle 11 and I get this error:
SQL Error [905] [42000]: ORA-00905: keyword not found.
Code:
SELECT *
INTO SAJ.ETMP_TESTE
FROM SAJ.ESAJOBJETO O
WHERE CDOBJETO = 'P800000000J03'
I read the Oracle docs and haven't found any obvious error in my statement.
https://docs.oracle.com/cd/B19306_01/appdev.102/b14261/selectinto_statement.htm
My objective is to create the table ETMP_TESTE with structure from ESAJOBJETO.
I checked user permission and user has permission to action.

You need create table and not select into for create a table based on the result of a query
CREATE TABLE SAJ.ETMP_TESTE
AS SELECT *
FROM SAJ.ESAJOBJETO O
WHERE CDOBJETO = 'P800000000J03'

This will create an empty table named ETMP_TESTE, with the structure of the SAJ.EASJOBJETO table.
CREATE TABLE ETMP_TESTE AS
SELECT *
FROM SAJ.EASJOBJETO
WHERE 1 = 0;
This does not handle contraints and primary keys and things like that, but it will get you the table structure. The 1 = 0 makes sure no data is copied.
If you need primary keys and the like, look into extracting the DDL for EASJOBJETO. Most SQL IDEs have that functionality built in. You can edit it to correct the table name and run the script and get everything.

Related

Error while creating View in SQL Database

I am working on database where I am trying to create view to get all records from Art table but i am getting error.
My SQL query for creating the view is as follows:
CREATE VIEW artInfo
AS
SELECT *
FROM art
WHERE artName = 'Guernica';
The syntax looks fine, just check table name and column name.
CREATE VIEW artInfo AS
SELECT *
FROM art
WHERE artName = 'Guernica';
Your code looks fine to me. I guess this error may come from TABLE artInfo ALREADY EXISTS if you run this code more than once.
CREATE OR REPLACE artInfo AS
SELECT * FROM art
WHERE artName = 'Guernica';
Otherwise, please update the error and RDBMS for your question.
The basic syntax for creating the view is
CREATE VIEW {viewName} AS {query}

How to create a table from a linked server into the local machine

I need to copy tables from a linked server onto my local machine. I am working in SQL management studio. The linked server is Oracle based. My end goal is to set up a stored proc that deletes a table if it exists and creates a new table in its place with refreshed data. This will be done for many tables as needed. The issue with the below code is that I get the error:
Incorrect syntax near the keyword 'SELECT'.
I am stuck at creating the table.
CREATE TABLE test AS
SELECT DUMMY
FROM OPENQUERY (LServer, '
Select *
from sourceT
');
The data in the dummy table is just one column with a single value "x". I have seen posts that suggest using a certain notation in naming the linked server table, like <server.database.schema.tablename> but this doesn't seem to work,even if I just run the select statement using the openquery. If I just run the select part in the script above, this does work.
CREATE TABLE test AS
Is valid in Oracle but not SQL Server
You want
-- if the table already exists drop it
DROP TABLE IF EXISTS test;
-- now create a table and load into it
SELECT DUMMY
INTO test
FROM OPENQUERY (LServer, '
Select *
from sourceT')

MS Access: Syntax error in CREATE TABLE statement

I am running this SQL query in MS Access:
CREATE TABLE EX_P_TEMP
AS (SELECT
EXPORT_POSTING_ID, IMPORT_POSTING_ID, DIS,
MILE_SAVED, IMPORT_AVAILABLE
FROM POTENTIAL_PAIRS);
Error:
Syntax error in CREATE TABLE statement.
Where did I go wrong?
That doesn't look like valid Access syntax. If you are trying to create a new table based on the results of a SELECT, try this intead:
SELECT EXPORT_POSTING_ID, IMPORT_POSTING_ID, DIS, MILE_SAVED, IMPORT_AVAILABLE
INTO EX_P_TEMP
FROM POTENTIAL_PAIRS;

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

Create Table by Copying Structure of Existing Table

I am trying to create a new table by copying an existing table in SQL Server 2008 using Management Studio. The existing table contains no data. I am using the following code but am receiving an error for Incorrect Syntax near AS. I am not sure what is wrong here. I am a SQL newb and any help would be appreciated. Thanks.
CREATE TABLE Drop_Centers_Detail
AS (Select * From Centers_Detail)
like this, however this will not create indexes and constraints
select * into Drop_Centers_Detail
from Centers_Detail
where 1 = 0
In Sql Server Managment Studio, right-click your existing table and select Script Table as > Create to > New Query Editor Window. This will give you a better starting script that you can use as the base for your new schema.
1) I would suggest generating a create script from the table you want to copy, and then run that on your destination database.
2) Write a Insert statement in another SQL Query window to import that data
Insert Into Database1.Table1(Field1, Field2)
Select Field1, Field2 From Database2.Table