https://stackoverflow.com/questions/337503/whats-the-best-practice-for-primary-keys-in-tables?rq=1


Em quinta-feira, 25 de janeiro de 2018, 'DenesL' via web2py-users <
web2py@googlegroups.com> escreveu:

> MS SQL server 2012 (at the top of my first post) using *appadmin* to
> display tables/records.
> Clear enough?.
>
>
> On Thursday, January 25, 2018 at 9:33:51 AM UTC-5, Ovidio Marinho wrote:
>>
>> Be clearer, which databases are you using as a legacy? And what kind of
>> operation do you want to do?
>>
>>
>>
>>
>>
>>                    [image: http://itjp.net.br] <http://itjp.net.br>
>>                      http://itjp.net.b <http://itjp.net.br>r
>>           *Ovidio Marinho Falcao Neto*
>>                  ovidio...@gmail.com
>>                             Brasil
>>
>>
>> 2018-01-25 9:46 GMT-03:00 'DenesL' via web2py-users <
>> web2py@googlegroups.com>:
>>
>>> Hi Ovidio,
>>>
>>> the issue is that appadmin seems to be generating improper links to
>>> display records in legacy databases.
>>> The sample code given to reproduce it, although not from a real scenario
>>> is syntactically correct.
>>>
>>> Can anyone else reproduce the issue?.
>>>
>>> Thanks,
>>> Denes
>>>
>>>
>>> On Wednesday, January 24, 2018 at 6:35:07 PM UTC-5, Ovidio Marinho wrote:
>>>>
>>>> What is the need for you to create a primary key in a field name or
>>>> char?
>>>> look this:
>>>> It defines, stores and returns a Table object called "person"
>>>> containing a field (column) "name". This object can also be accessed via
>>>> db.person, so you do not need to catch the return value.
>>>> id: Notes about the primary key
>>>>
>>>> Do not declare a field called "id", because one is created by web2py
>>>> anyway. Every table has a field called "id" by default. It is an
>>>> auto-increment integer field (starting at 1) used for cross-reference and
>>>> for making every record unique, so "id" is a primary key. (Note: the id
>>>> counter starting at 1 is back-end specific. For example, this does not
>>>> apply to the Google App Engine NoSQL.)
>>>>
>>>> Optionally you can define a Field of type='id' and web2py will use this
>>>> field as auto-increment id field. This is not recommended except when
>>>> accessing legacy database tables which have a primary key under a different
>>>> name. With some limitation, you can also use different primary keys using
>>>> the primarykey parameter. primarykey is explained shortly below.
>>>> http://www.web2py.com/books/default/chapter/29/06/the-databa
>>>> se-abstraction-layer#id--Notes-about-the-primary-key
>>>>
>>>> a good practice of development is not creating primary keys are named,
>>>> another element would be important to social security + name ,for example.
>>>>
>>>> Hope this helps.
>>>>
>>>>
>>>>
>>>>
>>>>                    [image: http://itjp.net.br] <http://itjp.net.br>
>>>>                      http://itjp.net.b <http://itjp.net.br>r
>>>>           *Ovidio Marinho Falcao Neto*
>>>>                  ovidio...@gmail.com
>>>>                             Brasil
>>>>
>>>>
>>>> 2018-01-24 19:54 GMT-03:00 'DenesL' via web2py-users <
>>>> web2py@googlegroups.com>:
>>>>
>>>>> Testing web2py 2.16.01 installed from source on Windows 8 with Python
>>>>> 2.7.14
>>>>>
>>>>> I have two tables on MS SQL Server 2012, one is legacy, the other not:
>>>>>
>>>>> w2p.define_table('person',
>>>>>   Field('name', 'string', length=100, notnull=True),
>>>>>   Field('info', 'string', length=100),
>>>>>   primarykey=['name']
>>>>> )
>>>>>
>>>>> w2p.define_table('persona',
>>>>>   Field('name', 'string', length=100, notnull=True),
>>>>>   Field('info', 'string', length=100)
>>>>> )
>>>>>
>>>>> The appadmin shows the records for both tables but the legacy anchors
>>>>> to display each record are being incorrectly generated as:
>>>>>
>>>>> <a href="<function <lambda> at 0x00000000071AAEB8>/person?nam
>>>>> e=Ana">Ana</a>
>>>>>
>>>>> http://10.0.0.27:8000/test/appadmin/select/%3Cfunction%20%
>>>>> 3Clambda%3E%20at%200x00000000071AAEB8%3E/person?name=Ana
>>>>>
>>>>> Regards,
>>>>> Denes
>>>>>
>>>>> --
>>>>> Resources:
>>>>> - http://web2py.com
>>>>> - http://web2py.com/book (Documentation)
>>>>> - http://github.com/web2py/web2py (Source code)
>>>>> - https://code.google.com/p/web2py/issues/list (Report Issues)
>>>>> ---
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "web2py-users" group.
>>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>>> an email to web2py+unsubscr...@googlegroups.com.
>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>
>>>>
>>>> --
>>> Resources:
>>> - http://web2py.com
>>> - http://web2py.com/book (Documentation)
>>> - http://github.com/web2py/web2py (Source code)
>>> - https://code.google.com/p/web2py/issues/list (Report Issues)
>>> ---
>>> You received this message because you are subscribed to the Google
>>> Groups "web2py-users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to web2py+unsubscr...@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>> --
> Resources:
> - http://web2py.com
> - http://web2py.com/book (Documentation)
> - http://github.com/web2py/web2py (Source code)
> - https://code.google.com/p/web2py/issues/list (Report Issues)
> ---
> You received this message because you are subscribed to the Google Groups
> "web2py-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to web2py+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>


-- 




                   [image: http://itjp.net.br] <http://itjp.net.br>
                     http://itjp.net.b <http://itjp.net.br>r
          *Ovidio Marinho Falcao Neto*
                 ovidio...@gmail.com
                            Brasil

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to