# how to display data that have no unique key?

**URL:** <https://forum.servoy.com/t/how-to-display-data-that-have-no-unique-key/15576>\
**Category:** Classic Servoy\
**Created:** [February 26, 2012, 2:49pm UTC](https://forum.servoy.com/t/how-to-display-data-that-have-no-unique-key/15576 "2012-02-26T14:49:14Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![hilgers](https://avatars.discourse-cdn.com/v4/letter/h/6de8d8/32.png) [@hilgers](https://forum.servoy.com/u/hilgers)\
**Post date:** [February 26, 2012, 2:49pm UTC](https://forum.servoy.com/t/how-to-display-data-that-have-no-unique-key/15576/1 "2012-02-26T14:49:14Z")

</div>

I’m trying to display data from a database view (in this case MS-SQL 2008) which provides a list of records which has NO unique key to identify each row.  
This view was provided to simplify reporting and dispaying of the undelying data structure.

First of all: I don’t want to discuss the data structure ![:D]( "Very Happy") AND I can’t change anything in the database… ![:(]( "Sad")  
Using the view on a form and filtering the data, the form shows the correct number of records and all match the search criteria.

This is what servoy seems to do (taken from the Performance data log):

```auto
Find 
select top 201 logon1 from MyView where logon1 = ? order by logon1 asc

Load foundset 
select top 4 logon1, id, typ, scope, typ2, delegator_id, logon2, [Start], [Stop] from MyView where logon1 in (?, ?, ?)

```

But this are not the same records that you get if you issue an identical SQL SELECT in the/a SQL-editor…  
In my tests I got 3 records which contained one duplicated record. The result seems to be depending on “how wrong” I’m defining the row ident columns (so that Servoy feels happy to show any data from that view).

therefore:  
a) it makes me a bit “nervous” (I’m pretty new in Servoy) that Servoy seems to present just wrong data if your PK definitions are not ok  
b) do I really need to issue a “manual” SQL and create the according form on the fly via solution model?

thx in advance  
Jo

---

<div class="post-metadata">

**Author:** ![ngervasi](https://avatars.discourse-cdn.com/v4/letter/n/f9ae1b/32.png) [@ngervasi](https://forum.servoy.com/u/ngervasi)\
**Post date:** [February 27, 2012, 10:19am UTC](https://forum.servoy.com/t/how-to-display-data-that-have-no-unique-key/15576/2 "2012-02-27T10:19:43Z")

</div>

You just have to figure out the correct row identificators, as a last resort try to set each and every column as row\_ident.

---

<div class="post-metadata">

**Author:** ![AlanBourke](https://avatars.discourse-cdn.com/v4/letter/a/b5a626/32.png) [@AlanBourke](https://forum.servoy.com/u/AlanBourke)\
**Post date:** [February 27, 2012, 10:24am UTC](https://forum.servoy.com/t/how-to-display-data-that-have-no-unique-key/15576/3 "2012-02-27T10:24:02Z")

</div>

> Servoy seems to present just wrong data if your PK definitions are not ok

Well, yes. But that’s not a Servoy issue - Servoy uses Hibernate for its ORM layer, and Hibernate needs correct PK information, and it couldn’t really work any other way.

---

<div class="post-metadata">

**Author:** ![hilgers](https://avatars.discourse-cdn.com/v4/letter/h/6de8d8/32.png) [@hilgers](https://forum.servoy.com/u/hilgers)\
**Post date:** [February 28, 2012, 1:45pm UTC](https://forum.servoy.com/t/how-to-display-data-that-have-no-unique-key/15576/4 "2012-02-28T13:45:47Z")

</div>

Using all/more colums is not an option because the performance (at least in this case) would be terribly slow.

Coming back to part b) of my question ![;-)]( "Wink")

do I really need to use rawsql + SOM to configure the form on the fly?

just wondering…  
thx a lot

---

<div class="post-metadata">

**Author:** ![Jan\_Aleman](https://avatars.discourse-cdn.com/v4/letter/j/4af34b/32.png) [@Jan\_Aleman](https://forum.servoy.com/u/Jan_Aleman)\
**Post date:** [February 28, 2012, 9:30pm UTC](https://forum.servoy.com/t/how-to-display-data-that-have-no-unique-key/15576/5 "2012-02-28T21:30:41Z")

</div>

Why not stick it in an html field?

Create a label put it on your form make it big enough.  
Use the getAs html function on the dataset to get the data (check the example code for an example)  
put it on the label. Done!

> hilgers:  
> Using all/more colums is not an option because the performance (at least in this case) would be terribly slow.
> 
> Coming back to part b) of my question ![;-)]( "Wink")
> 
> do I really need to use rawsql + SOM to configure the form on the fly?
> 
> just wondering…  
> thx a lot

---

<div class="post-metadata">

**Author:** ![rgansevles](https://avatars.discourse-cdn.com/v4/letter/r/3d9bf3/32.png) [@rgansevles](https://forum.servoy.com/u/rgansevles)\
**Post date:** [March 6, 2012, 10:26am UTC](https://forum.servoy.com/t/how-to-display-data-that-have-no-unique-key/15576/6 "2012-03-06T10:26:53Z")

</div>

Alternatively, you can select the data (databaseManager.getDatasetByQquery) and convert it to a data source (dataset.createDataDource).

There is also databaseManager.createDataSourceByQuery() to do both above in 1 step.

Data sets do not need unique rows.

Rob

---

<div class="post-metadata">

**Author:** ![hilgers](https://avatars.discourse-cdn.com/v4/letter/h/6de8d8/32.png) [@hilgers](https://forum.servoy.com/u/hilgers)\
**Post date:** [March 7, 2012, 5:17pm UTC](https://forum.servoy.com/t/how-to-display-data-that-have-no-unique-key/15576/7 "2012-03-07T17:17:57Z")

</div>

Rob,  
“databaseManager.createDataSourceByQuery()” seems to be what I was looking for!

I’m having a strong and long-time background in FoxPro and things which are absolutely simple to be done in FoxPro (e.g. "display a list and don’t care what’s in it) are sometimes hard to find in Servoy - and even harder to explain to servoy people ![;-)]( "Wink")

THX all!

---

<div class="post-metadata">

**Author:** ![AlanBourke](https://avatars.discourse-cdn.com/v4/letter/a/b5a626/32.png) [@AlanBourke](https://forum.servoy.com/u/AlanBourke)\
**Post date:** [March 8, 2012, 9:02am UTC](https://forum.servoy.com/t/how-to-display-data-that-have-no-unique-key/15576/8 "2012-03-08T09:02:31Z")

</div>

You can get away with it in the FoxPro world because of the way DBF files work, they have the concept of the record number even if you don’t have an actual field that uniquely identifies rows. Having said that, IMO it’s a good idea to define an auto-incrementing integer id field for every FoxPro table anyway. I realise that in this case you cannot change the FoxPro data, however.

---

<div class="post-metadata">

**Author:** ![hilgers](https://avatars.discourse-cdn.com/v4/letter/h/6de8d8/32.png) [@hilgers](https://forum.servoy.com/u/hilgers)\
**Post date:** [March 8, 2012, 6:31pm UTC](https://forum.servoy.com/t/how-to-display-data-that-have-no-unique-key/15576/9 "2012-03-08T18:31:34Z")

</div>

Alan,

I know the conceptional differences between Fox/DBF and SQL-(server) databases especially regarding needed PKs… ![;-)]( "Wink")

For me it just was hard to find out that servoy handles datasources used in the designers (which are updateable) differently than the ones defined as queries.

nevertheless THX!
