Click here to Skip to main content
15,566,065 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I was making a Table in SSMS with multiple columns with drop-down options (Active/Inactive). I was able to create only one column with True/False. I dont know how to make it Active/Inactive

What I have tried:

I was able to create a Column as True/False.
Posted
Updated 10-Mar-21 20:58pm

1 solution

You can't makes it "Active" or "Inactive" directly as that would mean "adding a datatype" to SQL, and you can't do that.

What you actually do it create a Statuses Table:
ID      INT, IDENTITY
Status  NVARCHAR(8)
And fill it with the possible statuses:
ID    Status
1     Active
2     Inactive
You then add a reference to the ID column of that table in your "main" SQL table as a FOREIGN KEY.
The main table values are then prevented from being any status other than those you list in the Statuses table.
If you need the text you just use a JOIN:
SQL
SELECT m.UserName, s.Status 
   FROM MainTable m
   JOIN Statuses s ON m.StatusID = s.ID
To change it from active to inactive, you change the value in the main table
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900