mirror of https://github.com/nocodb/nocodb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 lines
8.5 KiB
1 lines
8.5 KiB
"use strict";(self.webpackChunknoco_docs=self.webpackChunknoco_docs||[]).push([[9933],{3905:(e,t,a)=>{a.d(t,{Zo:()=>p,kt:()=>u});var r=a(67294);function i(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}function n(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),a.push.apply(a,r)}return a}function o(e){for(var t=1;t<arguments.length;t++){var a=null!=arguments[t]?arguments[t]:{};t%2?n(Object(a),!0).forEach((function(t){i(e,t,a[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(a)):n(Object(a)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(a,t))}))}return e}function l(e,t){if(null==e)return{};var a,r,i=function(e,t){if(null==e)return{};var a,r,i={},n=Object.keys(e);for(r=0;r<n.length;r++)a=n[r],t.indexOf(a)>=0||(i[a]=e[a]);return i}(e,t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);for(r=0;r<n.length;r++)a=n[r],t.indexOf(a)>=0||Object.prototype.propertyIsEnumerable.call(e,a)&&(i[a]=e[a])}return i}var s=r.createContext({}),d=function(e){var t=r.useContext(s),a=t;return e&&(a="function"==typeof e?e(t):o(o({},t),e)),a},p=function(e){var t=d(e.components);return r.createElement(s.Provider,{value:t},e.children)},c="mdxType",m={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},y=r.forwardRef((function(e,t){var a=e.components,i=e.mdxType,n=e.originalType,s=e.parentName,p=l(e,["components","mdxType","originalType","parentName"]),c=d(a),y=i,u=c["".concat(s,".").concat(y)]||c[y]||m[y]||n;return a?r.createElement(u,o(o({ref:t},p),{},{components:a})):r.createElement(u,o({ref:t},p))}));function u(e,t){var a=arguments,i=t&&t.mdxType;if("string"==typeof e||i){var n=a.length,o=new Array(n);o[0]=y;var l={};for(var s in t)hasOwnProperty.call(t,s)&&(l[s]=t[s]);l.originalType=e,l[c]="string"==typeof e?e:i,o[1]=l;for(var d=2;d<n;d++)o[d]=a[d];return r.createElement.apply(null,o)}return r.createElement.apply(null,a)}y.displayName="MDXCreateElement"},49893:(e,t,a)=>{a.r(t),a.d(t,{assets:()=>s,contentTitle:()=>o,default:()=>m,frontMatter:()=>n,metadata:()=>l,toc:()=>d});var r=a(87462),i=(a(67294),a(3905));const n={title:"Primary Key",description:"Understanding Primary Key in NocoDB!"},o=void 0,l={unversionedId:"setup-and-usages/primary-key",id:"version-0.109.7/setup-and-usages/primary-key",title:"Primary Key",description:"Understanding Primary Key in NocoDB!",source:"@site/versioned_docs/version-0.109.7/030.setup-and-usages/100.primary-key.md",sourceDirName:"030.setup-and-usages",slug:"/setup-and-usages/primary-key",permalink:"/0.109.7/setup-and-usages/primary-key",draft:!1,editUrl:"https://github.com/nocodb/nocodb/tree/develop/packages/noco-docs/docs/versioned_docs/version-0.109.7/030.setup-and-usages/100.primary-key.md",tags:[],version:"0.109.7",sidebarPosition:100,frontMatter:{title:"Primary Key",description:"Understanding Primary Key in NocoDB!"},sidebar:"tutorialSidebar",previous:{title:"Formulas",permalink:"/0.109.7/setup-and-usages/formulas"},next:{title:"Display Value",permalink:"/0.109.7/setup-and-usages/display-value"}},s={},d=[{value:"What is a Primary Key ?",id:"what-is-a-primary-key-",level:2},{value:"What is the use of Primary Key ?",id:"what-is-the-use-of-primary-key-",level:2},{value:"Primary Key in NocoDB",id:"primary-key-in-nocodb",level:2},{value:"What if Primary Key was missing?",id:"what-if-primary-key-was-missing",level:2},{value:"Example : Primary Key & optional system fields during new table creation",id:"example--primary-key--optional-system-fields-during-new-table-creation",level:4},{value:"Example : Show System Fields",id:"example--show-system-fields",level:4},{value:"Can I change the Primary Key to another column within tables ?",id:"can-i-change-the-primary-key-to-another-column-within-tables-",level:2}],p={toc:d},c="wrapper";function m(e){let{components:t,...a}=e;return(0,i.kt)(c,(0,r.Z)({},p,a,{components:t,mdxType:"MDXLayout"}),(0,i.kt)("h2",{id:"what-is-a-primary-key-"},"What is a Primary Key ?"),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},"A primary key is a special database table column designated to uniquely identify each table record.")),(0,i.kt)("h2",{id:"what-is-the-use-of-primary-key-"},"What is the use of Primary Key ?"),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},"As it uniquely identifies an individual record of a table, it is used internally by NocoDB for all operations associated with a record")),(0,i.kt)("h2",{id:"primary-key-in-nocodb"},"Primary Key in NocoDB"),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},"Primary Key that gets defined / used in NocoDB depends on how underlying table was created. Summary is captured below")),(0,i.kt)("ol",null,(0,i.kt)("li",{parentName:"ol"},"From UI, Create new table / Import from Excel / Import from CSV",(0,i.kt)("ol",{parentName:"li"},(0,i.kt)("li",{parentName:"ol"},"An ",(0,i.kt)("inlineCode",{parentName:"li"},"ID")," ","[datatype: Integer]"," system field created by default during table creation is used as primary key"),(0,i.kt)("li",{parentName:"ol"},"Additional system fields ",(0,i.kt)("inlineCode",{parentName:"li"},"created-at"),", ",(0,i.kt)("inlineCode",{parentName:"li"},"updated-at")," are inserted by default & can be omitted optionally; these fields can be deleted after table creation"))),(0,i.kt)("li",{parentName:"ol"},"Connect to existing external database",(0,i.kt)("ol",{parentName:"li"},(0,i.kt)("li",{parentName:"ol"},"Existing ",(0,i.kt)("inlineCode",{parentName:"li"},"primary key")," field defined for a table is retained as is; NocoDB doesn't insert a new ID field"),(0,i.kt)("li",{parentName:"ol"},"Additional system fields ",(0,i.kt)("inlineCode",{parentName:"li"},"created-at"),", ",(0,i.kt)("inlineCode",{parentName:"li"},"updated-at")," are not inserted by default"))),(0,i.kt)("li",{parentName:"ol"},"Import from Airtable",(0,i.kt)("ol",{parentName:"li"},(0,i.kt)("li",{parentName:"ol"},"Airtable record ID is marked as primary key for imported records, and is mapped to field ",(0,i.kt)("inlineCode",{parentName:"li"},"ncRecordId")," ","[datatype: varchar]"),(0,i.kt)("li",{parentName:"ol"},"If a new record is inserted after migration & if ncRecordId field was omitted during record insertion - auto generated string will be inserted by NocoDB"),(0,i.kt)("li",{parentName:"ol"},"Computed hash value for the entire record is stored in system field ",(0,i.kt)("inlineCode",{parentName:"li"},"ncRecordHash")),(0,i.kt)("li",{parentName:"ol"},"Additional system fields ",(0,i.kt)("inlineCode",{parentName:"li"},"created-at"),", ",(0,i.kt)("inlineCode",{parentName:"li"},"updated-at")," are not inserted by default"))),(0,i.kt)("li",{parentName:"ol"},"Create new table using SDK / API",(0,i.kt)("ol",{parentName:"li"},(0,i.kt)("li",{parentName:"ol"},"No default primary key field is introduced by NocoDB. It has to be explicitly specified during table creation (using attribute ",(0,i.kt)("inlineCode",{parentName:"li"},"pk: true"),")")))),(0,i.kt)("h2",{id:"what-if-primary-key-was-missing"},"What if Primary Key was missing?"),(0,i.kt)("p",null,"It is possible to have a table without any primary key. "),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},"External database table can be created without primary key configuration."),(0,i.kt)("li",{parentName:"ul"},"New table can be created using SDK / API without primary key\nIn such scenario's, new records can be created in NocoDB for this table, but records can't be updated or deleted ","[as there is now way for NocoDB to uniquely identify these records]")),(0,i.kt)("h4",{id:"example--primary-key--optional-system-fields-during-new-table-creation"},"Example : Primary Key & optional system fields during new table creation"),(0,i.kt)("img",{width:"596",alt:"image",src:"https://user-images.githubusercontent.com/35857179/189113679-481bceab-8957-4c5d-a38c-9940f03cfd7e.png"}),(0,i.kt)("h4",{id:"example--show-system-fields"},"Example : Show System Fields"),(0,i.kt)("img",{width:"309",alt:"image",src:"https://user-images.githubusercontent.com/35857179/189113907-871f7ab0-9bb2-4f04-a726-2d9feb56892e.png"}),(0,i.kt)("h2",{id:"can-i-change-the-primary-key-to-another-column-within-tables-"},"Can I change the Primary Key to another column within tables ?"),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},"You can't update Primary Key from NocoDB UI. You can reconfigure it at database level directly & trigger ",(0,i.kt)("inlineCode",{parentName:"li"},"meta sync")," explicitly.")))}m.isMDXComponent=!0}}]); |