{"id":1032,"date":"2024-07-31T10:10:48","date_gmt":"2024-07-31T08:10:48","guid":{"rendered":"https:\/\/blog.sutilweb.eu\/?page_id=1032"},"modified":"2024-07-31T10:10:48","modified_gmt":"2024-07-31T08:10:48","slug":"09-llaves-y-atributos-unicos","status":"publish","type":"page","link":"https:\/\/sutilweb.eu\/index.php\/databases\/diseno-de-bases-de-datos\/09-llaves-y-atributos-unicos\/","title":{"rendered":"09. Llaves y atributos \u00fanicos"},"content":{"rendered":"\n<p>Una <strong>llave<\/strong> es un <strong>identificador<\/strong> que permite hacer \u00fanico a un <strong>registro de informaci\u00f3n<\/strong>. Principalmente tenemos dos tipos de <strong>llaves:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Llaves primarias<\/strong><\/li>\n\n\n\n<li><strong>Llaves for\u00e1neas<\/strong><\/li>\n<\/ul>\n\n\n\n<!--more-->\n\n\n\n<h3 class=\"wp-block-heading\">1. Llaves primarias<\/h3>\n\n\n\n<p>Las <strong>llaves primarias<\/strong> van a identificar a un <strong>registro<\/strong> como \u00fanico dentro de la <strong>entidad<\/strong> a la que va a pertenecer. En nuestro listado de atributos se le suele poner las siglas <strong><em>pk<\/em><\/strong> (<strong>Primary Key<\/strong>) en ingl\u00e9s, delante del atributo que vaya a ser la llave principal.<\/p>\n\n\n\n<p><strong>Llave principal<\/strong> puede ser el DNI, un n\u00famero de tlfo, una clave de estudiante cuando nos inscribimos a una escuela.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. Llaves for\u00e1neas<\/h3>\n\n\n\n<p>Las <strong>llaves for\u00e1neas<\/strong> permiten la relaci\u00f3n entre el registro de una <strong>entidad<\/strong> con el de otra, de tal manera que podamos hacer esa relaci\u00f3n, por ejm, en un <em>sistema de gesti\u00f3n<\/em> podemos tener personas, que podr\u00edan ser estudiantes, profesores y administrativos, estos perfiles van a tener una <strong>llave,<\/strong> y en la <strong>entidad<\/strong> donde almacenamos la informaci\u00f3n de las personas, en lugar de ver f\u00edsicamente el nombre de profesor, estudiante o administrativo, vamos a ver el <strong>id<\/strong> o <strong>identificador<\/strong> al que hace referencia, por lo que lo que va a ser la <strong>llave primaria<\/strong> en el registro de tipos de personas, ser\u00e1 la <strong>llave for\u00e1nea<\/strong> en el registro de personas, porque ese campo permite conectar ambas <strong>entidades,<\/strong> y saber cual es el valor de ese <strong>id<\/strong> en la <strong>tabla<\/strong> correspondiente del <strong>cat\u00e1logo.<\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Atributos \u00fanicos<\/h2>\n\n\n\n<p>En algunas ocasiones vamos a tener la necesidad de que algunos <strong>atributos<\/strong> de nuestras <strong>entidades<\/strong> sean <strong>\u00fanicos,<\/strong> es decir, no existan datos duplicados con el mismo valor en ese <strong>atributo,<\/strong> y sin que necesariamente sea una <strong>llave primaria<\/strong> o una <strong>llave for\u00e1nea.<\/strong> Para ello tenemos el concepto de <strong>atributo \u00fanico.<\/strong> Esta caracter\u00edstica se utiliza a menudo para asegurarse que los datos sean consistentes y que no haya duplicados en la <strong>entidad,<\/strong> por ejm, para que un usuario no pueda crear dos cuentas diferentes con un mismo correo, o con un mismo tlfo, tambi\u00e9n pueden ser <strong>atributos \u00fanicos<\/strong> el DNI, o un alias, los n\u00fameros de las matr\u00edculas de los autom\u00f3viles&#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Una llave es un identificador que permite hacer \u00fanico a un registro de informaci\u00f3n. Principalmente tenemos dos tipos de llaves:<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":1009,"menu_order":8,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"class_list":["post-1032","page","type-page","status-publish","hentry"],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false},"uagb_author_info":{"display_name":"Sutil Web","author_link":"https:\/\/sutilweb.eu\/index.php\/author\/sutilweb\/"},"uagb_comment_info":0,"uagb_excerpt":"Una llave es un identificador que permite hacer \u00fanico a un registro de informaci\u00f3n. Principalmente tenemos dos tipos de llaves:","_links":{"self":[{"href":"https:\/\/sutilweb.eu\/index.php\/wp-json\/wp\/v2\/pages\/1032","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sutilweb.eu\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/sutilweb.eu\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/sutilweb.eu\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sutilweb.eu\/index.php\/wp-json\/wp\/v2\/comments?post=1032"}],"version-history":[{"count":2,"href":"https:\/\/sutilweb.eu\/index.php\/wp-json\/wp\/v2\/pages\/1032\/revisions"}],"predecessor-version":[{"id":1034,"href":"https:\/\/sutilweb.eu\/index.php\/wp-json\/wp\/v2\/pages\/1032\/revisions\/1034"}],"up":[{"embeddable":true,"href":"https:\/\/sutilweb.eu\/index.php\/wp-json\/wp\/v2\/pages\/1009"}],"wp:attachment":[{"href":"https:\/\/sutilweb.eu\/index.php\/wp-json\/wp\/v2\/media?parent=1032"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}