Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modify Sqlite Table Column NOT NULL to NULL

Tags:

sqlite

I am looking for something similar to this but I'm using sqlite3. I have tried:

sqlite> UPDATE JOBS SET JOB_TYPES = NULL;

But I got "constraint failed". Am I doing it the correct way?

I want to change the current "NOT NULL" to "NULL".

like image 956
Sylar Avatar asked Apr 11 '15 21:04

Sylar


People also ask

How do you change a NOT NULL column to NULL in SQL?

All you need to do is to replace [Table] with the name of your table, [Col] with the name of your column and TYPE with the datatype of the column. Execute the command and you are allowed to use NULL values for the specified column. That is all it takes to switch between NULL and NOT NULL .

How do I insert a NULL value in a NOT NULL column?

Code Inspection: Insert NULL into NOT NULL column You cannot insert NULL values in col1 and col2 because they are defined as NOT NULL. If you run the script as is, you will receive an error. To fix this code, replace NULL in the VALUES part with some values (for example, 42 and 'bird' ).

How do you update a column as NULL in SQL?

To set a specific row on a specific column to null use: Update myTable set MyColumn = NULL where Field = Condition. This would set a specific cell to null as the inner question asks.


1 Answers

SQLite has almost no ALTER TABLE support.

The easiest method to change a table is to create a new table, and copy the data over:

CREATE TABLE Jobs2(..., JOB_TYPES NULL, ...);
INSERT INTO Jobs2 SELECT * FROM Jobs;
DROP TABLE Jobs;
ALTER TABLE Jobs2 RENAME TO Jobs;
like image 175
CL. Avatar answered Sep 22 '22 05:09

CL.