how do you restrict number of rows for a particular value
in a column.For example:there is a table called
fruits,having apples,bananas ,papayas.I dont want to have
more than 100 apples in that table ,so how can u restrict
number of rows for apple to hundred?
Answer Posted / ashwin
You can create a sequence named seq_fruit as below .
create sequence seq_fruit
increment by 1
start with 1
maxvalue 100
minvalue 1
cycle
cache 10
if the current count ie currval of seq_fruit is 100 and
after this if u r inserting a new row in fruit table as
following
insert into fruit values(seq_fruit.nextval,30,40);
after the execution of this statement next value for apple
will be entered as 1 and not 101.
The cycle keyword will avoid the count of fruit column to go
beyond 100.
| Is This Answer Correct ? | 0 Yes | 1 No |
Post New Answer View All Answers
What is substitution variable in pl sql?
How to display the current date in sql?
how many sql ddl commands are supported by 'mysql'? : Sql dba
What are different types of tables in sql?
What are the two types of exceptions in pl/sql?
What is the difference between sql and mysql?
How do I view a procedure in sql?
how to shut down the server with 'mysqladmin'? : Sql dba
Can we create table in function?
What is a unique constraint?
What is composite data type in pl sql?
What is the use of partition by in sql?
How is a process of pl/sql compiled?
How to run pl/sql statements in sql*plus?
what are the differences among rownum, rank and dense_rank? : Sql dba