Add a column with a default value to a table in Oracle SQL


In some situation, you need to add some Default value to a Column in a Table in SQL. For example, In "Login" table, if there is a "username" column which is used to store the username, but if the username is not yet saved then "username" should have by default value "GUEST". So, Let's see how to do it in Oracle SQL.

CREATE TABLE Login ( ID int NOT NULL, USERNAME varchar(255) DEFAULT 'GUEST', PASSWORD varchar(255), LAST_LOGIN_ON date DEFAULT sysdate );

In the above query, two columns "username" and "LAST_LOGIN_ON" have been given default values "GUEST" and sysdate respectively.

Solution Worked 0 UpvotesUpvote


Solution Didn't Worked 0 DownvotesDownvote



Play 2048 Game Online

Search Tags