Constraint to one of the primary keys as foreign key Table1: grid_col (col_id,f_id,f_value) 
    (col_id,f_id) is primary key. 

Table2: grid (grid_id,col_id,text) 
    (grid_id) is primary key. 


I want to have a constraint for grid that, col_id should be present in grid_col. I can't have foriegn key constraint here.
I can create a function constraint which scans the grid_col while inserting in grid but in that case it increases the chances of having deadlock.
How to add a constriant here?
You could create a TRIGGER on the grid table that will do an outer join on the inserted values and the grid_col table.This should give you NULL values for non-matched records which you can than remove from the grid table.