insert NULL values to database

RMAG news

Certainly! If you want to insert some NULL values into your database, you can modify the INSERT statement to include NULL in place of the actual values for any column that allows NULL values. Here’s an example based on your current Books table structure:

INSERT INTO Books (BookID, Title, Author, ISBN, Price, InStock)
VALUES (6, ‘The Hobbit’, ‘J.R.R. Tolkien’, NULL, 8.99, TRUE),
(7, NULL, ‘Agatha Christie’, ‘9780007136834’, 12.99, FALSE),
(8, ‘War and Peace’, NULL, ‘9781400079988’, NULL, TRUE);

In this example:

For the book with BookID 6, the ISBN is set to NULL.
For the book with BookID 7, the Title is set to NULL.
For the book with BookID 8, the Author and Price are set to NULL.

Remember, you can only insert NULL values into columns that are defined to accept NULL values in the database schema. If a column is defined as NOT NULL, attempting to insert a NULL value will result in an error.

Leave a Reply

Your email address will not be published. Required fields are marked *