Home Python C Language C ++ HTML 5 CSS Javascript Java Kotlin SQL DJango Bootstrap React.js R C# PHP ASP.Net Numpy Dart Pandas Digital Marketing

DEFAULT Constraint



SQL DEFAULT Constraint


A DEFAULT constraint in SQL is used to specify a default value for a column in a table. This constraint ensures that if a value is not explicitly provided for the column when inserting a new row, the default value will be used instead.

Here's a basic example of how to use DEFAULT constraint in SQL:


 CREATE TABLE Employees (
    EmployeeID INT PRIMARY KEY,
    FirstName VARCHAR(50),
    LastName VARCHAR(50),
    Gender CHAR(1) DEFAULT 'U', -- U stands for Unknown
    HireDate DATE DEFAULT GETDATE() -- Sets default value to current date
 );
      

In this example:

It's important to note that not all database systems use GETDATE(); the function for retrieving the current date might differ depending on the SQL flavor you're using. Similarly, the syntax for DEFAULT constraints can vary slightly between different database management systems.



Advertisement





Q3 Schools : India


Online Complier

HTML 5

Python

java

C++

C

JavaScript

Website Development

HTML

CSS

JavaScript

Python

SQL

Campus Learning

C

C#

java