Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (55.6k points)

Can anyone tell me how to create gender column in SQL?

1 Answer

0 votes
by (119k points)
edited by

Here is the syntax to create a gender column in SQL:

Create table table_name (

Gender Varchar (10) check (gender in ('Female','Male'))

Here we use CHECK constraint with GENDER column so that you cannot enter any entry other than Male or Female.

If you want to add a gender column to an already existing table:

ALTER TABLE TableName

                ADD CONSTRAINT myCheckConstraint CHECK (gender in ('Female','Male'))

If you want to learn SQL and writing SQL queries, I suggest this SQL server certification Course by Intellipaat that provides Instructor-led training, certification, and also job assistance.

Related questions

0 votes
1 answer
0 votes
1 answer
asked Jul 25, 2019 in SQL by Tech4ever (20.3k points)
0 votes
1 answer
0 votes
1 answer
asked May 5, 2020 in SQL by Sudhir_1997 (55.6k points)
0 votes
1 answer
asked May 3, 2020 in SQL by Sudhir_1997 (55.6k points)

Browse Categories

...