web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / SQL table- indexing, p...
Power Apps
Answered

SQL table- indexing, primary, date

(0) ShareShare
ReportReport
Posted on by 1,532

Hi all

Just testing SQL db for first time in PA and I got few questions

 

1/ Primary key (set data type to int., is identity true, increment 1)

Is this save way to prevent duplicates in primary key column? Does anyone test it in multi user- multi device app? 

 

2/ Unique index column

Just test that but it looks a bit dangerous to me. Once I tried to add same value in unique column it just error out my patch code in PA. I was hoping for some error message or at least insert nothing.I know I can prevent duplicate in PA but question is: is it worth using it? Or are you using it?

 

3/ Date data

Just tested the date data type column. I have insert date with Today() with no problem. Today date is inserted in SQL table but no matter what I do or format it in PA I get blank label. What a shame... So what data type do you use for dates or times in sql? 

 

Categories:
  • Meneghino Profile Picture
    6,949 on at

    1) Yes, very safe

     

    2) It is always worth ensuring data is correct in the Azure DB.  Today you use PowerApps, tomorrow you may use something else but the data is aways there.  I suggest you check for duplicates before you allow the user to trigger a Patch operation.  If there are duplicates show a message to the user instead of patching.

     

    3) Use date, again it is more imporant to have the correct data.  There is a workaround for this here:

    https://baizini-it.com/blog/index.php/2017/09/28/powerapps-and-azure-sql-database-current-issues/

    See point 2 of the post

  • Sienna Profile Picture
    1,532 on at

    @Meneghino

    1/ Thanks for confirmation

     

    2/ That is exactlly why I want to do it correctly but I'm a bit scared of that PA crashing the code. The problem might happend if the app will be used by multiple users and both users add same value at a same time

     

    3/ So far it doesn't work for me... I haven't tried to format it in the sql yet but refresh didn't help at all

    tbl.pngsql.pngpa.png

  • timl Profile Picture
    37,409 Super User 2026 Season 2 on at

    Hi @Sienna

     

    I frequently use the datetime datatype and I've never had a problem with this datatype.

  • Sienna Profile Picture
    1,532 on at

    Hi @timl

    Tried that, even all other date related datatypes... Nothing worked for me. Only workaround I found is to use datatype  decimal() or bigint, Patch dated with Value(Today()) and display it by formating it back to datum with Text() function. But I really don't want to do it this way for exactly the same reason as mentioned by @Meneghino in 2) point

  • Meneghino Profile Picture
    6,949 on at

    3/ You need to add a calculated column as an integer type with value yyyymmdd, or for exmple text yyyy-mm-dd calculated from your date column.

    Then show this column with corrected formatting in your PA, but do not patch to it obviously.  You need to patch to the original date column.  This way the data is correct but it will also show.

  • Sienna Profile Picture
    1,532 on at

    @Meneghino

    3/ I have looked at it and I will have to decide which option I will chose. To be honest I'm trying to keep the table as simple as possible and avoiding adding extra columns. I know there are always problems with dates in sql from previous posts. It looks like once they fixed them they'll appear again later on so I'm thinking now to only use value of the dates saved as integer (bigint) which I think would prevent any future bugs with SQL. I'm sure this will also fixed the issues with filtering and other flaws however the date won't be shown in SQL table. It is now either simplicity or date in sql

     

    2/ What is your opinion about that situation what I pointed out in 2nd point?

  • Verified answer
    Sienna Profile Picture
    1,532 on at

    Ok so I've done some simple tests for this. I have insert 2 timers trigered by 1 button to simulate duplicate entry at same time by multiple users on multiple devices. "name" column is set for unique index in sql, id is primary with is dentity to yes and incremet to1. Both timers have same Patch code

     

    If(LookUp('[dbo].[NameTbl]', name= "peter", name)="peter", 
    UpdateContext({startT:false}),
    Patch('[dbo].[NameTbl]', Defaults('[dbo].[NameTbl]'),{name: "peter",dateC:Value(Now())}));
    UpdateContext({startT:false})

    1/ By changing name in one of the timer I wasn't able to create duplicates in ID. But as you can see from the picture there is a tiny diference between time. I don't know if that delay is done by PA or by SQL server to prevent duplicates in primary key. I'm confident now that the primary key is safe for duplicates

    test.png

     

    2/ The simple prevention for duplicate in powerapps didn't stop crashing the code when column in SQL is set to unique. Besides there is no decent way to prevent duplicates by multi users on multiple devices. It would be nice to get some error message instead of crashing the code and basicaly crashing the whole app

    crash.png

     

    3/ I decided to use value of date-datetime to record dates. So far the dates are not very reliable in SQL. Value of the date is so far the most reliable way saved as integer in SQL. I'm sure we can transfer the value into a date format even in sql but for now I will use only one column with value date

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 234 Super User 2026 Season 2

#2
WarrenBelz Profile Picture

WarrenBelz 207 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 169

Last 30 days Overall leaderboard