SQLite User Forum

DROP TABLE followed by CREATE TABLE does not work
Login

DROP TABLE followed by CREATE TABLE does not work

(1) By Interrobang on 2022-06-17 00:36:44 [link] [source]

I am creating a database.  I want to insert a column in a particular place in the table structure.  Since there's no data in the table, I figured I could just dro the table and recreate it.  So, in SQLite Studio, I tried executing this query:

drop table payments;
CREATE TABLE payments (
    pkey           INTEGER            PRIMARY KEY AUTOINCREMENT,
    vendor_key      INTEGER           DEFAULT NULL,            
    person_key    integer             DEFAULT NULL,
    payment_date   DATE               NOT NULL,
    amount         DOUBLE             NOT NULL,
    check_number   INT (11)           DEFAULT NULL,
    purpose        TEXT               NOT NULL,
    allocation_key INTEGER            DEFAULT NULL,
    project_key    INTEGER            DEFAULT NULL,
    payment_method TEXT               NOT NULL,
    budget_key     [INTEGER UNSIGNED] DEFAULT NULL,
    fund_key       INTEGER            DEFAULT NULL
);

I get an error saying the table "payments" already exists.  I tried wrapping the DROP TABLE line in a transaction, but I got the same error.  What do I have to do to get this to work?

(Yes, I know I can run the two statements separately, but I think there's something I should know about SQlite that this illustrates, and I'd like to know what that is.)

P.S.  Is there a guide to the use of markdown?  I had to use plain text in this message because the query did not appear on separate lines.

(2) By Larry Brasfield (larrybr) on 2022-06-17 00:45:30 in reply to 1 [link] [source]

Is there a guide to the use of markdown?

Markdown Guide

Regarding your non-P.S. problem: If what you say is true, it represents a SQLite Studio problem. Nothing published by the SQLite project would behave so badly.

(3) By Interrobang on 2022-06-17 00:57:31 in reply to 2 [link] [source]

Thanks very much. What database management tool would you recommend?

(4) By Interrobang on 2022-06-17 01:09:26 in reply to 2 [link] [source]

I asked this on Reddit, and someone suggested highlighting the text in the query window to tell SQLite Studio to run everything. That worked. I definitely need a different tool.

(5) By Chris Locke (chrisjlocke1) on 2022-06-18 14:35:10 in reply to 4 [source]

DB4S (DB Browser for SQLite) is open-source and would run this as you expect. However, you'd need to press the 'Write Changes' button, which can get a bit annoying.

https://i.imgur.com/FMJtZ7v.png

It can be downloaded from here: https://sqlitebrowser.org/dl/

For the avoidance of doubt, this program is not affiliated, supported by or endorsed by anyone working for SQLite. Its just a program that works with SQLite databases.