Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to disable My existing Record where EmpolyID=1 Instead of delete. And I Also Retrieve All disable record from SQLdatabase table.
i'm using C# for FrantEnd

What I have tried:

I have No idea. How i can do this
Posted
Updated 5-Apr-18 7:19am

Try adding a column to your table called [Active] and set it to 0 or 1 (False/True) as required.
You will need to include a WHERE clause when querying along the lines of
SQL
SELECT columns FROM theTable WHERE [Active] = 1
 
Share this answer
 
Comments
Fahid Zahoor 5-Apr-18 13:08pm    
which datatype i used for 0 or 1 in sql table
CHill60 5-Apr-18 18:47pm    
I'd use a byte or an integer
Maciej Los 6-Apr-18 3:38am    
A byte - definitely! An int has totally different range of values!
BTW: a5!
In the simplest form 'disabling' a row can be just a column which defines if the row is valid or invalid, just like explained in Solution 1.

However, sometimes the moment in time is also interesting. For example think about a bus ticket. When you acquire it, it's valid until some point in time. In other words there is a date and time when the validity ends. Until that time has passed the ticket is valid.

Another example is the employee. If an employee is inactive, is it interesting when that happened or is it enough just to know that the employee is inactive? If the moment is interesting then you probably should have a date field, Inactivated for instance. This field would store the date when the employee was marked as inactive. If this field is empty then the employee is active.

Querying such structure would mean something like:

Query active employees:
SQL
SELECT * FROM Employee e WHERE Inactivated IS NULL


Query inactive employees:
SQL
SELECT * FROM Employee e WHERE Inactivated IS NOT NULL


Query employees that were inactivated during last 5 days
SQL
SELECT * FROM Employee e WHERE Inactivated BETWEEN GETDATE() - 5 AND GETDATE()


If you decide to store the invalidity as a date, the examples mentioned above are just scratching the surface. So you might want to read more about date intervals and date handling in queries.
 
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