<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 14 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p
        {mso-style-priority:99;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";}
span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:Consolas;}
span.EmailStyle20
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>This thread confuses me. I&#8217;ve not worked with the Asterisk MySQL CDR, but have worked with SQL for years.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Every table should have a primary key. Is no column identified as a PK?<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>If there is a PK, you will not be able to designate another column as PK.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>If there is a PK, you don&#8217;t need to worry about Asterisk duplicating keys in that column&#8212;the database will not permit non-unique PKs.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>If (and this would be really weird) the table is created with no primary key, it shouldn&#8217;t be a problem to add the primary key constraint to a column IF there are no nulls or duplicates existing.<o:p></o:p></span></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span lang=EN style='font-size:10.0pt;font-family:"Arial","sans-serif";color:#1F497D'>--Don</span><span lang=EN style='color:#1F497D'><o:p></o:p></span></p><p class=MsoNormal><span lang=EN style='font-size:10.0pt;font-family:"Arial","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> asterisk-users-bounces@lists.digium.com [mailto:asterisk-users-bounces@lists.digium.com] <b>On Behalf Of </b>Leandro Dardini<br><b>Sent:</b> Thursday, December 06, 2012 12:50 PM<br><b>To:</b> rwheeler@artifact-software.com; Asterisk Users Mailing List - Non-Commercial Discussion<br><b>Subject:</b> Re: [asterisk-users] CDR - Freepbx - Safe to add primary key to table ?<o:p></o:p></span></p><p class=MsoNormal><o:p>&nbsp;</o:p></p><p>The reason I add a new column autoincrement is due to the fact I trust more mysql about uniquness than asterisk. <o:p></o:p></p><p>Leandro<o:p></o:p></p><p>I am typing from my mobile phone...<o:p></o:p></p><div><p class=MsoNormal>Il giorno 06/dic/2012 19:11, &quot;Ron Wheeler&quot; &lt;<a href="mailto:rwheeler@artifact-software.com">rwheeler@artifact-software.com</a>&gt; ha scritto:<o:p></o:p></p><div><div><p class=MsoNormal>It seems like a safe thing to do.<br>You could also ask about the impact of making an existing column a&nbsp; primary key, in a MySQL forum.<br><br>Leandro's solution seems to be a good one as well and does guarantee uniqueness.<br><br><br><br>Ron<br><br>On 06/12/2012 12:25 PM, Leandro Dardini wrote:<o:p></o:p></p></div><blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><p class=MsoNormal>Yes, go for it. However I have added another autoincrement column and created the primary key on it. On the other columns I need to search I have created just an index. <o:p></o:p></p><div><p class=MsoNormal><o:p>&nbsp;</o:p></p></div><div><p class=MsoNormal style='margin-bottom:12.0pt'>Leandro<o:p></o:p></p><div><p class=MsoNormal>2012/12/6 Olivier &lt;<a href="mailto:oza_4h07@yahoo.fr" target="_blank">oza_4h07@yahoo.fr</a>&gt;<o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:0in;margin-right:.5in;margin-bottom:0in;margin-left:.5in;margin-bottom:.0001pt'>Hello,<br><br>I need to develop an application that will query (mostly reading) an existing MySQL CDR database.<br>This database (named asteriskcdrdb) was created during Freepbx 2.10 install on my asterisk 1.8 setup.<br>This database has a single CDR table which is filled by Asterisk.<br><br>The tools I'm planning to use require this table to include a Primary Key.<br>Is it safe to Alter this table telling it to use UniqueID column as a Primary Key ?<br><br>(Sure, I'll test this on a database copy but I'm not confident my tests will cover everything)<br><br>Regards<br><br>--<br><br><o:p></o:p></p></div></div></blockquote></div></div></div></body></html>