How to Set Default Value in SQL

SQL Default

A Default Value in SQL (Structural Query Language) is a value set to be automatically assigned to a column if no value is specified when a new row is inserted into the table by a user.

Let’s set a default value in our books_2 table

CREATE TABLE books_2 
	(
		book_id INT NOT NULL AUTO_INCREMENT,
		title VARCHAR(100),
		Author_Name VARCHAR(100) DEFAULT 'Not Registered',
		pages INT,
		PRIMARY KEY(book_id)
	);

From the table above, the Author_Name column has a default vale of ‘Not Registered’ in a situation where a user insert a name without the Author_Name

Leave a Reply

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