I was trying to drop multiple tables from a database with the syntax: `
DROP TABLE IF EXISTS B,C,A;
But this produces a syntax error.
A comment mentioned enclosing names within backticks, that didn't work either.
`
cur.execute("DROP TABLE IF EXISTS `meta`,`urls`;")
sqlite3.OperationalError: near ",": syntax error
`
You have to issue a drop statement for each table.
Related
I am trying to move a table which resides in a certain schema to a different schema with the same table name. I have tried the following but they do not work:
rename <OLD_SCHEMA_NAME>.<TABLE_NAME> TO <NEW_SCHEMA_NAME>.<TABLE_NAME>;
The error that appears is:
SQL Error [42000]: invalid identifier chain for new name [line 1, column 100] (Session: 1722923178259251200)
and
ALTER TABLE <OLD_SCHEMA_NAME>.<TABLE_NAME> RENAME <NEW_SCHEMA_NAME>.<TABLE_NAME>;
The error that appears is:
SQL Error [42000]: syntax error, unexpected IDENTIFIER_PART_, expecting COLUMN_ or CONSTRAINT_ [line 1, column 62] (Session: 1722923178259251200)
Many Thanks!
According to Exasol documentation there is no way to move table between schemas using RENAME statement:
Schema objects cannot be shifted to another schema with the RENAME
statement. For example, 'RENAME TABLE s1.t1 TO s2.t2' is not allowed.
I would move the table this way:
create table <NEW_SCHEMA_NAME>.<TABLE_NAME>
like <OLD_SCHEMA_NAME>.<TABLE_NAME>
including defaults
including identity
including comments;
insert into <NEW_SCHEMA_NAME>.<TABLE_NAME>
select *
from <OLD_SCHEMA_NAME>.<TABLE_NAME>;
drop table <OLD_SCHEMA_NAME>.<TABLE_NAME>;
Not sure how this happened, but a column got created named: "`". (just the back tick). When I attempt to drop this column, I end up with a syntax error.
Outside of taking a SQL dump and fixing the dump in a text editor, Does anybody have a suggestion to fix this query?
ALTER TABLE tableName DROP COLUMN "`";
You need to escape the inner backtick with another backtick, so:
alter table tableName drop column ````;
I have a table A with some columns in Sybase IQ. One of the columns is named "Comment".
Whenever I select that column:
select Comment from A
I got the error:
[Error Code: 102, SQL State: 42W04] SQL Anywhere Error -131: Syntax error near 'Comment'
I am able to select other columns without issues. Could you advise the reason and solution? Thank you
Try
select "Comment" from A
COMMENT is a reserved word in Sybase IQ.
Here is the link explaining your problem.
Some keywords in SQL are also reserved words. To use a reserved word
in a SQL statement as an identifier, you must enclose the word in
double quotes. Many, but not all, of the keywords that appear in SQL
statements are reserved words. For example, you must use the following
syntax to retrieve the contents of a table named SELECT.
SELECT * FROM "SELECT"
I'm renaming two columns in two tables, both of which are named LEVEL, which is a reserved word.
What is confusing me greatly is that I am running an identical command on both these tables, but only one of them is failing. Here are the commands:
--this works
ALTER TABLE notificationsubscriptions RENAME COLUMN "LEVEL" TO nlevel;
--this doesn't
ALTER TABLE notifications RENAME COLUMN "LEVEL" TO nlevel;
The second statement results in the following error:
Error starting at line : 9 in command -
ALTER TABLE notifications RENAME COLUMN "LEVEL" TO nlevel
Error report -
SQL Error: ORA-00900: invalid SQL statement
00900. 00000 - "invalid SQL statement"
*Cause:
*Action:
Both these columns are of the same datatype (number). I am baffled - Why would this command work for one of these tables but not the other?
The database is running Oracle 10.2.
Try to remove any links that exist on this column from indexes and/or foreign key constraints
Drop indexes
Rename column
Create indexes with the new name of column
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