Intellipaat 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?

2 Answers

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.

0 votes
by (3.1k points)

To create gender column in SQL use the below query:

  • ALTER TABLE tells the database which table you want to change
  • ADD gender adds a new column called gender, which can store text values up to 10 characters long. You can change the size if you need to fit longer values.

ALTER TABLE TableName

ADD gender VARCHAR(10);

Related questions

0 votes
2 answers
asked May 5, 2020 in SQL by Sudhir_1997 (55.6k points)
0 votes
2 answers
0 votes
2 answers

1.2k questions

2.7k answers

501 comments

693 users

Browse Categories

...