# Error using form on database view

**URL:** <https://forum.servoy.com/t/error-using-form-on-database-view/12044>\
**Category:** Classic Servoy\
**Created:** [April 14, 2010, 1:34pm UTC](https://forum.servoy.com/t/error-using-form-on-database-view/12044 "2010-04-14T13:34:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Karel\_Broer](https://avatars.discourse-cdn.com/v4/letter/k/bcef8e/32.png) [@Karel\_Broer](https://forum.servoy.com/u/Karel_Broer)\
**Post date:** [April 14, 2010, 1:34pm UTC](https://forum.servoy.com/t/error-using-form-on-database-view/12044/1 "2010-04-14T13:34:16Z")

</div>

Hi everyone,

I’ve got an interesting issue here: I like to use a form with a database view as datasource.  
The view is created by this sql:

```auto
SELECT c.contact_id, c.first_name || ' ' || c.last_name As Name, 1 AS contact_chk FROM contacts c
UNION
SELECT p.company_id, p.name, 0 AS contact_chk FROM companies p

```

Servoy 5.1.2 shows the view correctly as a table and I can select the view as datasource for the form, but this error occurs when showing the form:

```auto
Form 'addrbk_addressbook_view_tbl' is based on table 'addressbook_view' which doesn't have a primary key.

```

How to make this work since the view data is retrieved from multiple tables?

Servoy 5.1.2  
MacOS X 10.6.3

---

<div class="post-metadata">

**Author:** ![pbakker](https://avatars.discourse-cdn.com/v4/letter/p/a4c791/32.png) [@pbakker](https://forum.servoy.com/u/pbakker)\
**Post date:** [April 14, 2010, 2:10pm UTC](https://forum.servoy.com/t/error-using-form-on-database-view/12044/2 "2010-04-14T14:10:42Z")

</div>

You need to mark a column or combination of columns in the view are row identifiers, so Servoy knows how to uniquely identify each row

---

<div class="post-metadata">

**Author:** ![patrick](https://avatars.discourse-cdn.com/v4/letter/p/b2d939/32.png) [@patrick](https://forum.servoy.com/u/patrick)\
**Post date:** [April 14, 2010, 2:19pm UTC](https://forum.servoy.com/t/error-using-form-on-database-view/12044/3 "2010-04-14T14:19:22Z")

</div>

I think you should (for your own sake) create some logic, that allows you distinguish one record from the other. For example, you could do something like this

```auto
create view karel_view as 
select 'companies' as table_name, company_id as id, company_name as name FROM companies
UNION 
select 'contacts' as table_name, contact_id as id, name_last as name FROM contacts

```

Then you use “table\_name” and “company\_id” as PK.

---

<div class="post-metadata">

**Author:** ![Karel\_Broer](https://avatars.discourse-cdn.com/v4/letter/k/bcef8e/32.png) [@Karel\_Broer](https://forum.servoy.com/u/Karel_Broer)\
**Post date:** [April 14, 2010, 2:30pm UTC](https://forum.servoy.com/t/error-using-form-on-database-view/12044/4 "2010-04-14T14:30:38Z")

</div>

Thanks guys! I didn’t know about the row\_ident option in the datasource properties, but now I know! ![:D]( "Very Happy")
