# Unable to drop a Column in SQLite

**URL:** <https://forum.xojo.com/t/unable-to-drop-a-column-in-sqlite/70994>\
**Category:** Databases\
**Created:** [July 2, 2022, 6:29am UTC](https://forum.xojo.com/t/unable-to-drop-a-column-in-sqlite/70994 "2022-07-02T06:29:40Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Emile\_Schwarz](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/90ced4/32.png) [@Emile\_Schwarz](https://forum.xojo.com/u/Emile_Schwarz)\
**Post date:** [July 2, 2022, 6:29am UTC](https://forum.xojo.com/t/unable-to-drop-a-column-in-sqlite/70994/1 "2022-07-02T06:29:40Z")

</div>

I tried the code below and some variations without success…

```auto

SQL_Cmd = "ALTER TABLE " + Table_Name + " DROP " + Column_Name + ";"

```

Yes, the two variables are filed with the correct values…

PS: DROP TABLE works fine (instead of ALTER TABLE…) so, it is really the SQL\_Cmd line that have a problem.

Ideas ?

Xojo 2021r2.1  
Monterey 12.4

---

<div class="post-metadata">

**Author:** ![Jean-Yves\_Pochez](https://forum.xojo.com/user_avatar/forum.xojo.com/jean-yves_pochez/32/21769_2.png) [@Jean-Yves\_Pochez](https://forum.xojo.com/u/Jean-Yves_Pochez)\
**Post date:** [July 2, 2022, 6:39am UTC](https://forum.xojo.com/t/unable-to-drop-a-column-in-sqlite/70994/2 "2022-07-02T06:39:30Z")

</div>

is there any error code that would help ?

---

<div class="post-metadata">

**Author:** ![Emile\_Schwarz](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/90ced4/32.png) [@Emile\_Schwarz](https://forum.xojo.com/u/Emile_Schwarz)\
**Post date:** [July 2, 2022, 6:40am UTC](https://forum.xojo.com/t/unable-to-drop-a-column-in-sqlite/70994/3 "2022-07-02T06:40:55Z")

</div>

I do not remember (I slept since yesterday evening). I check right now…

---

<div class="post-metadata">

**Author:** ![Emile\_Schwarz](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/90ced4/32.png) [@Emile\_Schwarz](https://forum.xojo.com/u/Emile_Schwarz)\
**Post date:** [July 2, 2022, 6:43am UTC](https://forum.xojo.com/t/unable-to-drop-a-column-in-sqlite/70994/4 "2022-07-02T06:43:13Z")

</div>

Apparently, I have other troubles; the first attempts says nothing (it may work), the second told me about … missing TABLE…

I reboot the laptop since yesterday.

I come back in a bunch of minutes (coffee to drink).

---

<div class="post-metadata">

**Author:** ![Emile\_Schwarz](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/90ced4/32.png) [@Emile\_Schwarz](https://forum.xojo.com/u/Emile_Schwarz)\
**Post date:** [July 2, 2022, 6:55am UTC](https://forum.xojo.com/t/unable-to-drop-a-column-in-sqlite/70994/5 "2022-07-02T06:55:33Z")

</div>

Now it delete the TABLE…

To better understand:

 ![image](https://forum.xojo.com/uploads/default/original/2X/6/698feaa39e95ca6bdb12c18cc60dd32337d09e1e.jpeg)

I have a button to drop the selected Column (Right ListBox): both ListBoxes must have a selected Row or the button stop.

BTW: the other background color is yellow (20%), but I see a white background instead…

---

<div class="post-metadata">

**Author:** ![Tim\_Hare](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_hare/32/176_2.png) [@Tim\_Hare](https://forum.xojo.com/u/Tim_Hare)\
**Post date:** [July 2, 2022, 6:58am UTC](https://forum.xojo.com/t/unable-to-drop-a-column-in-sqlite/70994/6 "2022-07-02T06:58:33Z")

</div>

SqLite does not support dropping a column. You have to create a copy of the table (along with its data), drop the original table, recreate the original without the column, and copy the data back (minus the column you’re dropping). Many sqlite tools do this for you behind the scenes, but in Xojo you have to do all the work yourself.

---

<div class="post-metadata">

**Author:** ![Emile\_Schwarz](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/90ced4/32.png) [@Emile\_Schwarz](https://forum.xojo.com/u/Emile_Schwarz)\
**Post date:** [July 2, 2022, 7:03am UTC](https://forum.xojo.com/t/unable-to-drop-a-column-in-sqlite/70994/7 "2022-07-02T07:03:13Z")

</div>

I saw that command in their documentation. Link: [ALTER TABLE DROP …](https://sqlite.org/lang_altertable.html)

You may be right, because I used at first [www.w2Schools.com/sql/](http://www.w2Schools.com/sql/) information… then when it does not worked, I checked [sqlite.org](http://sqlite.org) docs (doswnloaded yesterday afternoon).

```auto

SQL_Cmd = "ALTER TABLE Spare_Parts DROP COLUMN SRP;"

```

Get Syntax Error Near DROP.

Previous reports were because a debug line I add yesterday (and forgot since)… sorry.

---

<div class="post-metadata">

**Author:** ![Tim\_Hare](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_hare/32/176_2.png) [@Tim\_Hare](https://forum.xojo.com/u/Tim_Hare)\
**Post date:** [July 2, 2022, 7:36am UTC](https://forum.xojo.com/t/unable-to-drop-a-column-in-sqlite/70994/8 "2022-07-02T07:36:35Z")

</div>

It looks like the newest versions of sqlite support that syntax, but the version in use by Xojo does not. Xojo uses an older version of sqlite, which does not support that and will throw an error.

---

<div class="post-metadata">

**Author:** ![Emile\_Schwarz](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/90ced4/32.png) [@Emile\_Schwarz](https://forum.xojo.com/u/Emile_Schwarz)\
**Post date:** [July 2, 2022, 8:03am UTC](https://forum.xojo.com/t/unable-to-drop-a-column-in-sqlite/70994/9 "2022-07-02T08:03:40Z")

</div>

In 2022r1.1 SQLite version is 3.36  
The current version on [sqlite.org](http://sqlite.org) is 3.39 (2022-06-25).

Too bad.

---

<div class="post-metadata">

**Author:** ![SteveP](https://forum.xojo.com/user_avatar/forum.xojo.com/stevep/32/6872_2.png) [@SteveP](https://forum.xojo.com/u/SteveP)\
**Post date:** [July 2, 2022, 8:10am UTC](https://forum.xojo.com/t/unable-to-drop-a-column-in-sqlite/70994/10 "2022-07-02T08:10:52Z")

</div>

Supported from 3 35 and patched in 3.35.5:

[https://www.sqlite.org/releaselog/3\_35\_5.html](https://www.sqlite.org/releaselog/3_35_5.html)

---

<div class="post-metadata">

**Author:** ![Emile\_Schwarz](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/90ced4/32.png) [@Emile\_Schwarz](https://forum.xojo.com/u/Emile_Schwarz)\
**Post date:** [July 2, 2022, 8:28am UTC](https://forum.xojo.com/t/unable-to-drop-a-column-in-sqlite/70994/11 "2022-07-02T08:28:50Z")

</div>

Thank You Steve.

It works with Xojo 2022r1.1 !

I forgot why I do not want to use that version, but my code works there !

I can go on with that project.

PS: I forgot to read the Release notes… 🇺🇦

---

<div class="post-metadata">

**Author:** ![Rick\_Araujo](https://forum.xojo.com/user_avatar/forum.xojo.com/rick_araujo/32/251_2.png) [@Rick\_Araujo](https://forum.xojo.com/u/Rick_Araujo)\
**Post date:** [July 2, 2022, 11:12am UTC](https://forum.xojo.com/t/unable-to-drop-a-column-in-sqlite/70994/12 "2022-07-02T11:12:07Z")

</div>

> [@Emile\_Schwarz](#):
>
> `SQL_Cmd = "ALTER TABLE " + Table_Name + " DROP " + Column_Name + ";"`

This snippet misses the COLUMN.

`SQL_Cmd = "ALTER TABLE " + Table_Name + " DROP COLUMN " + Column_Name + ";"`

And yes, in older versions of the engine we renamed the old table to some temp name, recreated a new table with the new structure, copied the data from temp to the new one, and deleted the temp table.

---

<div class="post-metadata">

**Author:** ![Rick\_Araujo](https://forum.xojo.com/user_avatar/forum.xojo.com/rick_araujo/32/251_2.png) [@Rick\_Araujo](https://forum.xojo.com/u/Rick_Araujo)\
**Post date:** [July 2, 2022, 11:30am UTC](https://forum.xojo.com/t/unable-to-drop-a-column-in-sqlite/70994/13 "2022-07-02T11:30:54Z")

</div>

> [@Emile\_Schwarz](#):
>
> In 2022r1.1 SQLite version is 3.36

Drop column (and engine 3.36) is present since Xojo 2021r3

> **[SQLite 3.36.0 New Features – Xojo Programming Blog](https://blog.xojo.com/2021/11/18/sqlite-new-features/)**

---

<div class="post-metadata">

**Author:** ![Emile\_Schwarz](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/90ced4/32.png) [@Emile\_Schwarz](https://forum.xojo.com/u/Emile_Schwarz)\
**Post date:** [July 2, 2022, 12:05pm UTC](https://forum.xojo.com/t/unable-to-drop-a-column-in-sqlite/70994/14 "2022-07-02T12:05:36Z")

</div>

Both works with last Xojo.

MessageBox("SQLite version = " + App.gDB.LibraryVersion)

---

<div class="post-metadata">

**Author:** ![AlbertoD](https://forum.xojo.com/letter_avatar_proxy/v4/letter/a/dbc845/32.png) [@AlbertoD](https://forum.xojo.com/u/AlbertoD)\
**Post date:** [July 2, 2022, 12:05pm UTC](https://forum.xojo.com/t/unable-to-drop-a-column-in-sqlite/70994/15 "2022-07-02T12:05:41Z")

</div>

I hate when I can not find the information I’m looking for in a few searches.

I searched for Xojo Sqlite version, I looked at the Release Notes for 2022r1 and 2022r1.1 and I can’t find the Sqlite version in the latest Xojo.

Does anyone know where to find that information on the documentation?

---

<div class="post-metadata">

**Author:** ![Rick\_Araujo](https://forum.xojo.com/user_avatar/forum.xojo.com/rick_araujo/32/251_2.png) [@Rick\_Araujo](https://forum.xojo.com/u/Rick_Araujo)\
**Post date:** [July 2, 2022, 12:07pm UTC](https://forum.xojo.com/t/unable-to-drop-a-column-in-sqlite/70994/16 "2022-07-02T12:07:04Z")

</div>

> [@Emile\_Schwarz](#):
>
> Both works with last Xojo.

What’s “both”?

I guess this broken syntax doesn’t:

> [@Emile\_Schwarz](#):
>
> SQL\_Cmd = "ALTER TABLE " + Table\_Name + " DROP " + Column\_Name + “;”

---

<div class="post-metadata">

**Author:** ![AlbertoD](https://forum.xojo.com/letter_avatar_proxy/v4/letter/a/dbc845/32.png) [@AlbertoD](https://forum.xojo.com/u/AlbertoD)\
**Post date:** [July 2, 2022, 12:08pm UTC](https://forum.xojo.com/t/unable-to-drop-a-column-in-sqlite/70994/17 "2022-07-02T12:08:36Z")

</div>

> [@Rick\_Araujo](#):
>
> What’s “both”?

> [@Rick\_Araujo](#):
>
> > [@Emile\_Schwarz](#):
> >
> > `SQL_Cmd = "ALTER TABLE " + Table_Name + " DROP " + Column_Name + ";"`
> 
> This snippet misses the COLUMN.
> 
> `SQL_Cmd = "ALTER TABLE " + Table_Name + " DROP COLUMN " + Column_Name + ";"`

Both commands, in Sqlite ‘COLUMN’ is optional.

---

<div class="post-metadata">

**Author:** ![Emile\_Schwarz](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/90ced4/32.png) [@Emile\_Schwarz](https://forum.xojo.com/u/Emile_Schwarz)\
**Post date:** [July 2, 2022, 12:08pm UTC](https://forum.xojo.com/t/unable-to-drop-a-column-in-sqlite/70994/18 "2022-07-02T12:08:42Z")

</div>

WITH AND WITHOUT COLUMN (and with the last Xojo).

@AlbertoD Read the entry above yours for the answer…

---

<div class="post-metadata">

**Author:** ![AlbertoD](https://forum.xojo.com/letter_avatar_proxy/v4/letter/a/dbc845/32.png) [@AlbertoD](https://forum.xojo.com/u/AlbertoD)\
**Post date:** [July 2, 2022, 12:11pm UTC](https://forum.xojo.com/t/unable-to-drop-a-column-in-sqlite/70994/19 "2022-07-02T12:11:03Z")

</div>

> [@Emile\_Schwarz](#):
>
> @AlbertoD Read the entry above yours for the answer…

Thank you, Emile, but how new users, without Xojo installed can know which version of SQLite is part of the released Xojo? Is there a place in the documentation for that?

- I can’t find it in the release notes
- I can’t find it in the system requirements
- I can’t find it in sqlite database documentation for Xojo

I’m used to search in Google for something, like ‘Xojo Sqlite Version’ and find the answer, but can’t find it this time.

---

<div class="post-metadata">

**Author:** ![Rick\_Araujo](https://forum.xojo.com/user_avatar/forum.xojo.com/rick_araujo/32/251_2.png) [@Rick\_Araujo](https://forum.xojo.com/u/Rick_Araujo)\
**Post date:** [July 2, 2022, 12:12pm UTC](https://forum.xojo.com/t/unable-to-drop-a-column-in-sqlite/70994/20 "2022-07-02T12:12:16Z")

</div>

> [@AlbertoD](#):
>
> Both commands, in Sqlite ‘COLUMN’ is optional.

I needed to check, and it’s really true for SQLITE:

 ![image](https://forum.xojo.com/uploads/default/original/2X/e/eca7ab902f8ad8edb1c63ba37d3cdc64bb5e08ef.png)

[Next page](https://forum.xojo.com/t/unable-to-drop-a-column-in-sqlite/70994.md?page=2)
