I have an exercises table with this schema:
CREATE TABLE exercises
(
id INTEGER NOT NULL,
name VARCHAR(255) NOT NULL,
workoutID INTEGER NOT NULL,
FOREIGN KEY (workoutID) REFERENCES workouts(id)
);
I want to delete the column workoutID but it won't let me delete it:
sqlite> ALTER TABLE exercises DROP workoutID;
Error: near "DROP": syntax error
Upon realizing I need to remove the constraints first I try:
sqlite> ALTER TABLE exercises DROP CONSTRAINT workoutID;
Error: near "DROP": syntax error
I followed this question to the letter: How to drop column with constraint?
But it doesn't work for me.
I can start over by dropping the whole table if I have to but I want to learn why this isn't working for me.
Any help and explanation is greatly appreciated.
Related
This question already has an answer here:
Create a table with a space in the name
(1 answer)
Closed 9 months ago.
I know what a syntax error is but cannot find any error when creating this table:
my code
CREATE TABLE branch supplier (
branch_id INT,
supplier_name VARCHAR(40),
supply_type VARCHAR(40),
PRIMARY KEY (branch_id, supplier_name),
FOREIGN KEY (branch_id) REFERENCES branch(branch_id) ON DELETE CASCADE
);
and the error I'm getting
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'supplier ( branch_id INT, supplier_name VARCHAR(40), supply_type ' at line 1
It is not allowed to use table names with space(s) unless you use `. This means you need to change this to...
CREATE TABLE `branch supplier`...
or to something without space, as example
CREATE TABLE branch_supplier...
This question already has answers here:
How to delete or add column in SQLITE?
(23 answers)
Closed 2 years ago.
sqlite> .schema autor
CREATE TABLE autor (ID INTEGER PRIMARY KEY, NOME TEXT, CIDADE TEXT, ESTADO TEXT, TELEFONE TEXT, idade number);
sqlite> alter table autor drop idade;
Error: near "drop": syntax error
(Also tried to use DROP COLUMN instead of DROP).
Please help, is that a bug ?
You can't do this with SQLite, because it does not support dropping columns. This is a documented limitation (emphasis mine):
Only the RENAME TABLE, ADD COLUMN, and RENAME COLUMN variants of the ALTER TABLE command are supported. Other kinds of ALTER TABLE operations such as DROP COLUMN, ALTER COLUMN, ADD CONSTRAINT, and so forth are omitted.
A possible workaround is to recreate another table with the correct structure, then copy the data, drop the old table and rename the new table:
create table autor_new (
id integer primary key,
nome text,
cidade text,
estado text,
telefone text
);
insert into autor_new select id, nome, cidade, estado, telefone from autor;
drop table autor; -- back it up first!
alter table autor_new rename to autor;
I am new to SQL and I am trying to run a CREATE TABLE query in Ms Access 2016 but I get an error saying that "mytablename" already exits which can't be true because I also ran a DROP TABLE "mytablename" query and I got an error saying "mytablename" does not exist. Please help. Point me in the right direction at least. Here is the CREATE TABLE query.
CREATE TABLE Team(
Team_ID AUTOINCREMENT UNIQUE NOT NULL,
Name VARCHAR(40) NOT NULL,
Origin VARCHAR(40) NOT NULL,
NetWorth CURRENCY NOT NULL,
PRIMARY KEY(Team_ID)
);
See check by VBA and check by SQL for check existence of your database.
If table exists you can recreate (drop and create again) table. Alternative way is to create table if table is not exist and do nothing if table exists.
I'm using the following code in Oracle 11g
alter table account_creation
drop constraint branch_code;
I get an error saying cannot drop constraint non existent constraint but when I check the table the NULL constraint still exists for that particular column
Am I using the correct syntax?
Use this syntax:
ALTER TABLE account_creation
MODIFY (branch_code varchar(10) NULL);
I always get the error on postgres sql can anyone help me
ERROR: Syntaxerror in „(“ LINE 4: Liga_Nr int(1),
^
********** ERROR **********
ERROR: Syntaxerror in „(“ SQL Status:42601 Symbol:79
Here is my code
DROP TABLE IF EXISTS Liga;
Create Table Liga(
Verband varchar(90),
Liga_Nr int(1),
PRIMARY KEY(Liga_Nr)
);
DROP TABLE IF EXISTS Spiel;
CREATE Table Spiel(
);
DROP TABLE IF EXISTS Verein;
CREATE Table Verein(
);
DROP TABLE IF EXISTS Spieler;
CREATE Table Spieler(
PRIMARY KEY(Spieler_ID)
);
Integer types don't accept a parameter. The correct code is:
Create Table Liga(
Verband varchar(90),
Liga_Nr int,
PRIMARY KEY(Liga_Nr)
);
If you want to store a small number, use smallint. You can read about numeric types here.