Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1erWlR-0000vq-0y for pgsql-general@arkaria.postgresql.org; Thu, 01 Mar 2018 22:33:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1erWlP-0002Df-GP for pgsql-general@arkaria.postgresql.org; Thu, 01 Mar 2018 22:33:23 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1erWlP-0002D6-2l for pgsql-general@lists.postgresql.org; Thu, 01 Mar 2018 22:33:23 +0000 Received: from mail-qk0-x243.google.com ([2607:f8b0:400d:c09::243]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1erWlM-0006Ef-2I for pgsql-general@lists.postgresql.org; Thu, 01 Mar 2018 22:33:21 +0000 Received: by mail-qk0-x243.google.com with SMTP id 130so9664765qkd.13 for ; Thu, 01 Mar 2018 14:33:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=4vD/tNU1y36paQ2eak2pKSfDSy4uf45UHYPBM9otikg=; b=A3s2gmdkczO72eGGflukYSQpCaNmftNWX1M99BVkIgRteQY6dMVNAuEGT90gqFV/IB EfbO40g5MEHBZQgRlT8aGffJnpejs5tJ2LgQRW8Cecjixea7gyjZb34qV8eznUDwBeqE cboX+VLHYT9ocyFKGLrwqI0SeHI1ziwn3LoiTD1W4LDuj/Uafb+aZf2RK5Bn92bJmGw3 gh9e0L5hFeO3rVq0IKHr/oA/pV5tqu8toIeBayFHdXyIpBGqpNat5/G4l9BHg5KKOiCF FWhm1fzGmosqzfSUlDUVa3my0o8j1WrKPJHPYgYwmyI7CpAdD3KwjhEdolafQFA3Peut jdEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=4vD/tNU1y36paQ2eak2pKSfDSy4uf45UHYPBM9otikg=; b=qsIcI7aEgNzro2VFIHrlsCB2dhr58Fy7C/aJWj0DQp2BGMOA6a0PY5JsYWVyd4pa3t oEvJ377G+SpjvWCbDOydia8LwMOg0heEkr1Lxqohlnj5blzFZqC/P0LDOUXCYqg216JC zQn3F5/T8/E/c3zixspB8OHoyVsAAwdW/1h34Ui25/39PxwpvdYlAZZJB+MY6gfEgaD8 H1Y2R5z6AjmkqCY9r2Km76Dz9/L+he3fgrAZHx8eCcTDQiCc+0JyV24ATLUu2SaqHDnD BarIRSVyH749blbCjm4x1TRRVZHhq9T01nqAL1MIyoKLtADl7XiOvbMN18+vCvxBpzgT 31Zg== X-Gm-Message-State: AElRT7Fvtk+tTbb9EyiPeMtGfQa2I/cNhJm8dXkS70leKYLZ53x4SQXr Mkb77gsmnY3vtKmD1Kb5IefnsZpm X-Google-Smtp-Source: AG47ELvlKSf/Go/0+6MixWWel2mUMA39XL8LpsN3zlFeSuJUOxKSC9qnJ+029KWvYoVhGGbrOFHRtA== X-Received: by 10.55.183.68 with SMTP id h65mr5128806qkf.345.1519943598529; Thu, 01 Mar 2018 14:33:18 -0800 (PST) Received: from [192.168.1.250] (host63.190-229-77.telecom.net.ar. [190.229.77.63]) by smtp.gmail.com with ESMTPSA id y58sm3681770qtb.92.2018.03.01.14.33.17 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Mar 2018 14:33:18 -0800 (PST) Subject: Re: Enforce primary key on every table during dev? To: pgsql-general@lists.postgresql.org References: <161e1761560-58a6-18e4b@webjas-vad211.srv.aolmail.net> <2580784f-3b8c-d044-3809-b4ca28993175@archidevsys.co.nz> From: marcelo Message-ID: Date: Thu, 1 Mar 2018 19:33:15 -0300 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 In-Reply-To: <2580784f-3b8c-d044-3809-b4ca28993175@archidevsys.co.nz> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-Antivirus: Avast (VPS 180301-10, 01/03/2018), Outbound message X-Antivirus-Status: Clean List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 01/03/2018 19:05 , Gavin Flower wrote: > On 02/03/18 06:47, Daevor The Devoted wrote: >> >> On Thu, Mar 1, 2018 at 2:07 PM, Rakesh Kumar > > wrote: >> >> >>     >Adding a surrogate key to such a table just adds overhead, >>     although that could be useful >>     >in case specific rows need updating or deleting without also >>     modifying the other rows with >>     >that same data - normally, only insertions and selections happen >>     on such tables though, >>     >and updates or deletes are absolutely forbidden - corrections >>     happen by inserting rows with >>     >an opposite transaction. >> >>     I routinely add surrogate keys like serial col to a table already >>     having a nice candidate keys >>     to make it easy to join tables.  SQL starts looking ungainly when >>     you have a 3 col primary >>     key and need to join it with child tables. >> >> >> I was always of the opinion that a mandatory surrogate key (as you >> describe) is good practice. >> Sure there may be a unique key according to business logic (which may >> be consist of those "ungainly" multiple columns), but guess what, >> business logic changes, and then you're screwed! So using a primary >> key whose sole purpose is to be a primary key makes perfect sense to me. > > I once worked in a data base that had primary keys of at least 4 > columns, all character fields, Primary Key could easily exceed 45 > characters.  Parent child structure was at least 4 deep. > > A child table only needs to know its parent, so there is no logical > need to include its parent and higher tables primary keys, and then > have to add a field to make the composite primary key unique!  So if > every table has int (or long) primary keys, then a child only need a > single field to reference its parent. > > Some apparently safe Natural Keys might change unexpectedly.  A few > years aback there was a long thread on Natural versus Surrogate keys - > plenty of examples were using Natural Keys can give grief when they > had to be changed!  I think it best to isolate a database from > external changes as much as is practicable. > > Surrogate keys also simply coding, be it in SQL or Java, or whatever > language is flavour of the month.  Also it makes setting up testdata > and debugging easier. > > I almost invariably define a Surrogate key when I design tables. > > > Cheers, > Gavin > > > > +5. I fully agree. --- El software de antivirus Avast ha analizado este correo electrónico en busca de virus. https://www.avast.com/antivirus