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


Please Help Members By Posting Answers For Below Questions

table structure: ---------------- col1 col2 ----- ----- 01-mar-2012 11:12:46 01-mar-2012 11:12:10 01-mar-2012 11:12:46 01-mar-2012 11:11:23 Write a query to display the result as shown below: col1 col2 ----- ----- 01-mar-2012 11:12:46 01-mar-2012 11:12:10

3338


List the different type of joins?

569


How many types of sql are there?

523


What are pl sql data types?

547


how to get a list of indexes of an existing table? : Sql dba

514






How do I run sql profiler?

584


Can we join same table in sql?

523


How can we solve sql error: ora-00904: invalid identifier?

697


which operator is used in query for pattern matching? : Sql dba

543


how can we encrypt and decrypt a data present in a mysql table using mysql? : Sql dba

641


How do you delete duplicates in sql query using rowid?

534


Do we need commit after truncate?

609


What is trigger in pl sql?

556


what is union? : Sql dba

580


Why primary key is required?

554