# Adding a Primary Key to a database table

**URL:** <https://forum.inductiveautomation.com/t/adding-a-primary-key-to-a-database-table/96380>\
**Category:** Ignition\
**Tags:** namedqueries\
**Created:** [September 24, 2024, 3:47pm UTC](https://forum.inductiveautomation.com/t/adding-a-primary-key-to-a-database-table/96380 "2024-09-24T15:47:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alex\_Ford-King](https://avatars.discourse-cdn.com/v4/letter/a/ebca7d/32.png) [@Alex\_Ford-King](https://forum.inductiveautomation.com/u/Alex_Ford-King)\
**Post date:** [September 24, 2024, 3:47pm UTC](https://forum.inductiveautomation.com/t/adding-a-primary-key-to-a-database-table/96380/1 "2024-09-24T15:47:49Z")

</div>

I am trying to add an id column to my database table. The instructuional videos did not mention how to assign a primary key in a named query. Everything i try gives me a syntax error. Can someone please share what the named query is supposed to look like for a primary key. Thanks

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [September 24, 2024, 3:53pm UTC](https://forum.inductiveautomation.com/t/adding-a-primary-key-to-a-database-table/96380/2 "2024-09-24T15:53:44Z")

</div>

You don't define primary keys in named queries. That is "DDL", data definition in your DB, not "DML", data management, which is what SELECT and UPDATE queries do.

If you are trying to **provide** a specific value for a primary key column, you'd do that just like any other value.

---

<div class="post-metadata">

**Author:** ![Alex\_Ford-King](https://avatars.discourse-cdn.com/v4/letter/a/ebca7d/32.png) [@Alex\_Ford-King](https://forum.inductiveautomation.com/u/Alex_Ford-King)\
**Post date:** [September 24, 2024, 4:03pm UTC](https://forum.inductiveautomation.com/t/adding-a-primary-key-to-a-database-table/96380/3 "2024-09-24T16:03:12Z")

</div>

I am trying to define one of the columns as the primary key column the same way the "Tank" table from the example project has "TankNo" as the key. If its not done in the Named Queries where do I establish it?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [September 24, 2024, 4:04pm UTC](https://forum.inductiveautomation.com/t/adding-a-primary-key-to-a-database-table/96380/4 "2024-09-24T16:04:52Z")

</div>

In whatever database management UI you normally use to create tables. If you know the SQL syntax, you can use the designer's Query browser, but it isn't very friendly.

(This stuff is somewhat DB brand-specific.)

I use JetBrains DataGrip, fwiw. (Multiplatform.)

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [September 24, 2024, 4:35pm UTC](https://forum.inductiveautomation.com/t/adding-a-primary-key-to-a-database-table/96380/5 "2024-09-24T16:35:05Z")

</div>

Don't take this the wrong way, but you should probably learn database basics before trying to use them in ignition. It will save you a lot of headache.
