Trying to duplicate a table without data [duplicate] - sql

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

Related

Cannot select columns by their names in PostgreSQL [duplicate]

This question already has answers here:
PostgreSQL "Column does not exist" but it actually does
(6 answers)
sql statement error: "column .. does not exist"
(1 answer)
Are PostgreSQL column names case-sensitive?
(5 answers)
Closed 10 months ago.
I downloaded a PostreSQL file that creates and populates the Chinoook database (a relatively well known database used for testing).
I then opened the file on sqliteonline (an online compiler where you can test SQL code).
Opening the SQL file created and populated all tables as expected. However, the following query throws an error:
SELECT ArtistId
FROM "Artist";
db error: ERROR: column "artistid" does not exist
Which is odd, because the column does exist in that table:
select *
from "Artist";
ArtistId
Name
1
AC/DC
2
Accept
3
Aerosmith
4
Alanis Morissette
5
Alice in Chains
How come I cannot select any columns by their names?

SQL not recognising table columns in ON statement [duplicate]

This question already has answers here:
Column doesnot exist error in PostgreSQL command
(1 answer)
Postgres query with uppercase letters in Column name
(1 answer)
Closed 11 months ago.
I have this SQL query:
SELECT "Segments.Id", "AggregatedValues.Segment"
FROM "Segments"
INNER JOIN "AggregatedValues" ON "Segments.Id" = "AggregatedValues.Segment";
And I get the following error:
ERROR: column "Segments.Id" does not exist
LINE 1: ... FROM "Segments" INNER JOIN "AggregatedValues" ON "Segments....
^
SQL state: 42703
Character: 99
This is EXTREMELY weird because the column DOES EXIST. The proof is that when selecting the column in the SELECT statement, no errors are thrown. It is also weird because if I change the order and say ON "AggregatedValues.Segment" = "Segments.Id" instead of ON "Segments.Id" = "AggregatedValues.Segment" then AggregatedValues.Segment appears as non existent even tho it also exists.
Any idea? I'm going mad
Thank you very much!!!!

Why does Access 2016 reject the syntax [duplicate]

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 ...

postgres constantly gives "schema does not exist" errors [duplicate]

This question already has answers here:
Are PostgreSQL column names case-sensitive?
(5 answers)
SQL query column does not exist error
(1 answer)
Strange behaviour in Postgresql
(1 answer)
Cannot simply use PostgreSQL table name ("relation does not exist")
(18 answers)
Postgres column does not exist
(1 answer)
Closed 5 years ago.
I managed to create a table in a schema FOO.
Whenever I then try and do anything, like even a basic select, I just get:
ERROR: schema "FOO" does not exist
SQL state: 3F000
Character: 15
I am running the select in the same edit window as I created (using pgAdmin4). I get the same error when I try and create a view call FOO.Info. Yet when I try and create a new table in FOO it works.
What's going on? I am using the same syntax to refer to the table in the select as the create.
# worked fine
CREATE TABLE "FOO"."Events"
(
...
# all these have the error
select * from "FOO"."Events";
select * from FOO.Events;
select * from Foo.Events;
postgres=# \dn
List of schemas
Name | Owner
--------+----------
foo | postgres
public | postgres
(2 rows)
I believe you created it as
create schema FOO;
which creates schema "foo", not "FOO"
And then you reference it as
select * from "FOO".table_name
so it is not found

Simple SQL statement in MS Access [duplicate]

This question already has an answer here:
MS Access 2010 SQL Select Into Calculated Column Issue
(1 answer)
Closed 6 years ago.
I'm trying what should be a simple task in Access. Basically to create a new table based on a string matching query. The Hazus_Schools table already exists in my database. The Hazus_Public does not, and I'm trying to create it. The PUBLIC field is a calculated column from another field. The following snippet
SELECT * FROM Hazus_Schools INTO Hazus_Public
WHERE Type = "PUBLIC";
Gives me the following error:
Syntax error in FROM clause
Any ideas what is wrong here?
The order of your INTO and FROM is off, see W3schools Select Into
Try the following:
SELECT *
INTO Hazus_Public
FROM Hazus_Schools
WHERE Type = "PUBLIC"