validate and restrict data in a bd

1

Friends, I have a question that I would like someone to give me a solution. I have a table created in bd postgres with campos id, name, code and state and I need to restrict and validate two fields.

the code field is of type string but it must save numbers only, that includes that the zero is read, for example that the code field being string stores 0001 but that DOES NOT save letter and so on. the state field must give three conditions. if it were 0 = canceled if it were 1 = working and if it were 2 = paralyzed. it is appreciated

    
asked by user92645 30.06.2018 в 20:47
source

1 answer

0

Change the data types in your table

If you already created it you must make an alter table or an update, if you want the code to save only numbers you can use a

ALTER TABLE nombredelatabla
modify codigo tinyint(4);

that to change the code field, and then only accept numeric characters as you search and on status you can do the following:

ALTER TABLE nombredelatabla
modify estado BOOLEAN;

and then using a canceled state is somewhat inefficient but you can take the 0 as false and any other value as true

I hope I have been helpful

    
answered by 30.06.2018 в 21:24