Primary key with PHPmysql database question

I know that the update of the primary key is a taboo subject, but I have a newsletter subscription form set up that works perfectly, but I can't understand how to create the primary key.  I tried to use the subscriber email address (because its unique, but when trying to add a function to update, I realize that the e-mail address may have to be updated.)

My question is how do I get a primary key that works when I'm relying on a form variable to create the folder and did so no control over the assignment of one?

Is it possible to have one assigned automatically when a Subscriber clicks on the submit button?

This is why it is always a good idea to use surrogate keys. You can just have the database generates a unique id. In MySQL, I think that there is a column with the auto_increment attribute. If you then get this id after insert, php has functions for this (mysql_insert_id() I think).

Tags: Dreamweaver

Similar Questions

  • disable the primary key with waterfall

    Hello everyone,

    I just want to know
    1. What is the effect after we diasble cascade a constraint primary key with the option?
    2 should rebuild us the index after you have enabled the constraint? How?

    Please explain with an example...

    Thanx

    2 should rebuild us the index after you have enabled the constraint? How?

    The index will be re-created for you automatically when you enable constraint even once:

    SQL> create table t (i integer constraint t_pk primary key)
    /
    Table created.
    
    SQL> select index_name, uniqueness from user_indexes where table_name = 'T'
    /
    INDEX_NAME                     UNIQUENES
    ------------------------------ ---------
    T_PK                           UNIQUE
    1 row selected.
    
    SQL> alter table t disable primary key cascade
    /
    Table altered.
    
    SQL> select index_name, uniqueness from user_indexes where table_name = 'T'
    /
    no rows selected.
    
    SQL> alter table t enable primary key
    /
    Table altered.
    
    SQL> select index_name, uniqueness from user_indexes where table_name = 'T'
    /
    INDEX_NAME                     UNIQUENES
    ------------------------------ ---------
    T_PK                           UNIQUE
    1 row selected.
    
    SQL> drop table t
    /
    Table dropped.
    
  • Adding primary keys with javascript.

    I have a database that has no metadata.

    We have the primary key definitions in an external system.

    The primary key information are easy to get.

    I want to update the relational model (and display) with the primary key information.

    Is it possible to update the primary key of infromation in the model of the relationship of Javascript?

    Hello

    You can try to settle for your use:

    // get table name
    tname = ...;
    //get pk name
    pkname = ....;
    table = model.getTableSet().getByName(tname);
    if(table !=n ull){
    index = table.createIndex();
    index.setName(pkname);
    index.setPK(true);
    // get column name - should iterate in case of multi column PK
    cname = ...;
    column = table.getElementByName(cname);
    if(column != null){
      index.add(column);
    }
    table.setDirty(true);
    }
    

    Philippe

  • Update primary key with waterfall

    Lets say I have 10 tables that have a foreign key defined, that everything points to a single table primary key.
    Now, I want to update the value of the primary key to another value, and I want all 10 tables to get this new value in their columns FK.
    Also, note also that some of these 10 tables can have this FK-value that is updated to PK-table.
    I can do this task with a good script?

    I would like to somehow in this way:
    Update PkTable set
    Pkcol=NewAvailableValue
    CASCADE;
    Right now I use the following approach:
    1. from table "user_constraints" find FK constraints binded to the primary change being key to find the list of tables.
    2 query each table if it has the PK value in their columns-FK, if has, then update the value allowed another PK-value.
    3. Update PK-value of primary key column of the table to the new value.
    4 validation.

    Maybe this will be useful: Tom Kyte: UPDATE CASCADE PACKAGE

  • A composite primary key with two KeyField: a rope and a sequential int.

    Hi all

    According to [url http://download.oracle.com/docs/cd/E17277_02/html/java/com/sleepycat/persist/model/PrimaryKey.html#sequence ()] sequence JavaDoc: a composite key class can also be used to substitute the sort order, but it can contain only a single key field which has one of the types mentioned previously.

    We strive to create a composite PK as follows:
    @Persistent
    public class ExamplePK {
        @KeyField(1) Integer seq;
        @KeyField(2) String admon;
    
        public String getAdmon() {
            return admon;
        }
    
        public void setAdmon(final String admon) {
            this.admon = admon;
        }
          public Integer getSeq() {
          return seq;
        }
          public void setSeq(final Integer seq) {
          this.seq = seq;
        }
    }
    
    @Entity
    public class ExamplePojo {
    
        // Relational fields
        @PrimaryKey(sequence="ExampleSeq")
        private ExamplePK idExample;
    
        public ExamplePK getIdExample() {
            return idExample;
        }
    
        public void setIdExample(final ExamplePK idExample) {
            this.idExample = idExample;
        }
    }
    but we get the following exception:
    java.lang.IllegalArgumentException:A composite key class used with a sequence may contain only a single integer key field: es.correos.ape.dao.notification.pojo.ExamplePK[Server1:1291138230743]
          at com.sleepycat.persist.impl.CompositeKeyFormat.getSequenceKeyFormat(CompositeKeyFormat.java:292)
          at com.sleepycat.persist.impl.PersistKeyAssigner.<init>(PersistKeyAssigner.java:39)
          at com.sleepycat.persist.impl.Store.getPrimaryIndex(Store.java:337)
          at com.sleepycat.persist.EntityStore.getPrimaryIndex(EntityStore.java:307)
    What we're doing wrong?

    ARO
    / Caesar.

    Caesar, I think that the wording of the javadoc and exception message is incorrect or at least confused, and I answer key for a future version.

    -mark

  • Two constraints of primary key of a table with two different constraint name

    Hi guys

    I am creating the table below

    Table name: TITLE_COPY

    Column name Copy_id Title_id Status

    Key type

    PKPK, FK
    UniqueNN, UNN, UNN
    CheckAvailable, destroyed, leased, reserved
    Table Ref FKTitle
    FK Ref ColTitle_id
    Data typeNumberNumberVarchar2
    Length101015

    The SQL statement below can create it

    CREATE TABLE title_copy (copy_id NUMBER (10),)

    title_id CONSTRAINT NUMBER (10) title_copy_title_id_fk title (title_id) REFERENCES.

    primary key constraint title_copy_title_id_pk title_id (copy_id)

    status VARCHAR2 (15) NOT NULL CONSTRAINT status_ck CHECK (status IN ('AVAILABLE', 'DESTROYED', 'RENTAL', 'RESERVED'))

    );

    Two primary keys (title_id, copy_id) are created with the same name of constraint (title_copy_title_id_pk) (-> table-level constraint). What happens if I want to have two different names of the primary key constraint, say title_copy_title_id_pk for the title_id column and title_copy_copy_id_pk for the copy_id column?

    I can do that with a column-level constraint? Something like below (complains about the additional primary key)

    CREATE TABLE title_copy (copy_id NUMBER (10) CONSTRAINT title_copy_copy_id_pk PRIMARY KEY,)

    constraint title_copy_title_id_pk primary key (title_id).

    title_id CONSTRAINT NUMBER (10) title_copy_title_id_fk title (title_id) REFERENCES.

    status VARCHAR2 (15) NOT NULL CONSTRAINT status_ck CHECK (status IN ('AVAILABLE', 'DESTROYED', 'RENTAL', 'RESERVED'))

    );

    In summary, I can define two primary keys with the name of different constraint in a column-level constraint?

    There are no two primary keys. There is a primary key made up of two columns - also called a composite key.

    A table can have at least a primary key. You can, if you wish, create a unique constraint on a different set of columns.

  • implement the primary key on the field of forms

    Hello experts,

    I have a form with deptno single base table.
    dept_name and deptno. DEPTNO is a primary key in the database table.
    When I get the records, it prevents to insert the value that is duplicated in the deptno text box when I insert or update.

    the form I create a block with the base table, apply the primary key property of this Dept block. is Yes.
    then I put the key property primary deptno fields to yes.
    When I get duplicate records and then save, it prevents insertion but I want the following:

    I run the form, when I enter the first record, if it exists in the table can prevent to insert. also after the first record was inserted.
    If I insert to new deptno even into the next record, it must also prevent.

    Please help me.

    Thank you
    Yoann

    You have built your data forms to help block the "data block Wizard? If so, it already identified DEPTNO as the PK column. If it does not, or you have built your data manually block, you can open the palette property for the DEPTNO element and set the primary key property Yes. When this property is set on an element, the corresponding property of block, primary to apply key must also be set to yes. Please remember, however, that the Act of mark the DEPTNO as a PK does not 'Real time' checking for duplicates. Checking for duplicates occur when validation occurs. If you need a real-time duplicate check, you will need to write code to allow audits in double 'real time '.

    There are numrous examples in the forum to check duplicate in real-time as well as examples on the Internet. A search on Google for 'Check' the locker double shaped will give you lots of good examples.

    Craig...

  • Primary key for the case in (NVARCHAR2 datatype) in Oracle 10 g

    I have primary keys in my database which are of type NVARCHAR2. By default, the data is inserted in these columns as case sensitive, which means the insertion of these two 'ABCD' and 'Abcd' is allowed.

    Can I change the settings in Oracle so that primary keys are working in sensitive cases? I tried Oracle to raise an error if someone is inserting "Abcd" and if there is already a record with primary key 'ABCD '.

    Note: I use Entity Framework.

    The simplest approach is probably to create a unique index on the UPPER (your_key) function, i.e.

    CREATE UNIQUE INDEX case_insensitive
        ON table_name ( UPPER( key_column_name ) );
    

    If you want to replace the queries to be case-sensitive, so, you can change the NLS_COMP and NLS_SORT for each session and create all your index with these NLS settings by default, but that complicates life in general.

    Either said by the way, do you really need to use the NVARCHAR2 data type? Your really using characters that cannot be represented in your character of database primary keys are defined?

    Justin

  • change a composite primary key


    Hello

    I have a table that has a composite primary key with 3 columns (col1, col2, col3)

    Now I need to change the primary key (col1, col2, col4) remove composite col3 replace with col4

    col1 col2 COL3 COL4 col5
    1onexpDFD
    1oneTherepDFD
    1onezpSD
    1onempamplifier
    1onenpTry

    There are thousands of records in the table in the format above. How to make this change?

    Thank you.

    In this case, you will need to establish that if the change to the primary key makes sense - if so, you'll have to remove some lines to remove duplicates. I think that if this requirement has been raised at a request of the company, they will (should) have indicated what lines need to be maintained.

    If it is not sensible, you will need to go to the one who asked for the change and get them to change their mind or tell you what to do with duplicate lines.

    Out of curiosity, why did you change the primary key?

  • using a sequence as the primary key

    I use a sequence for the primary key of the database for dimensions (following Kimball methodology). In ODI, I define another unique key as principal. It will not let you select check null = true and therefore a sequence can serve as primary. Someone at - it something differently.

    ss396s wrote:
    I use a sequence for the primary key of the database for dimensions (following Kimball methodology). In ODI, I define another unique key as principal. It will not let you select check null = true and therefore a sequence can serve as primary. Someone at - it something differently.

    You must follow the rules on the sequence
    1 > it cannot be run on the source
    2 > may not be a part of your key update
    3 > check not the null check box should not be selected
    4 > separate box must not be activated

    If you use a sequence for the primary key for the database, and then identify another or several columns are coming from the source and use that you can only identify a row. Use these columns as your key to update.

    Thank you
    Fati

  • [ADF, JDev12.1.3] Mastering the form with detail tables: questions about Insertion/deletion, commit / rollback, primary key, handling,...

    Hallo,

    I have a panelTabbed with 4 tabs. In the 1st tab, there is a master form while each of the other tabs, there is a secondary table. Each tab "reads" vo.

    Please see here http://digilander.libero.it/flattit82/OTN_FILES/VoInTabs.png

    I created the graphichs/layout and now it's time to take care of the management of the transaction.

    In the master tab / form

    1)

    Here, I would put a button to remove the master record.

    When I delete a record in the primary table an automatism in the database (MS SQL Server) will automatically delete any registration which are linked to it in the detail tables.

    Could the automated system as this causes problems?

    In the Details tabs / tables

    2)

    I would put a button in each row to delete the line delivering. Can I just drag-and - drop, like button, af line: table the operation "Delete" of the VO istance detail used to create the af: table?

    3)

    If Yes, by clicking on the button performs the default delete operation. But if need to perform some actions before you run the deletion (or, in General, any other operation), how can I do?

    4)

    To create a folder that I use Create or CreateInsert? And what are the differences between them?

    5)

    When I create a new record I need set the value of a field of the VO on which is based the af: table. He filed, let's call it RowDetNumber, is not displayed in the af: table, because it doesn't have be filled in by the user. Mut value is calculated and set "secretly" before posting the new line to the database table. In particular, its value must be calculated as

    Select max (RowDetNumber) + 1

    of table_on_which_VO_is_based

    where some_conditions_on_fields_of_the_same_VO


    For example

    The VO selects all of the records that have FkId =: value. If value = 3, VO selection records:

    ID RowDetNumber OtherFields FkId

    1   3     1             ...

    2   3     2             ...

    3   3     3             ...

    4   3     4             ...

    The new record must be RowDetNumber = 5.

    I would like to know how permorm this.

    In general

    6)

    If the database tables have 1 or more triggers I have to take care of something?

    7)

    On the book "development of Web Applications with Oracle ADF Essentials - Sten E. Vesterli", I have read it could be problems when you use tables of database non-Oracle with auto-increment fields.

    The advice of author uncheck the 'Required' box in the model.

    All tables in my database have a primary keys that are auto-increment... so I uncheck the "mandatory"?

    8)

    In general how do I set these fields? I have to put in OT, VO or both?

    Thank you

    Federico

    Hello

    (1) you will need to re - question child iterators so that they do not look stale data

    (2) Yes. Ensure that the table is PPRed after deleting the line (should happen automatically if ChangeEventPolicy on iterator is set to ppr)

    (3) double click on the button and it creates a bean managed for you. It allows you to check a box to generate the code he would run to remove the line. Everything you put in front of the generated code is your code before

    (4) in the case of tables, use createInsert as it adds the new line to the rowset (transaction)

    (5) suggest to do this use a database trigger and the data attribute value DBSequence VO type

    (6) do not 'drop table' issue in SQL (sorry, couldn't resist ;-))

    (7) If you follow the advice of the author, Yes. What it does, I have it does not throw an exception if a value is missing in the validation of the line

    (8) usually you set whatever it is at the level of the OS and put only things on VO if you want to override the default value for a specific behavior


    Frank

  • How to insert multiple lines in viewobject with primary key?

    Hello

    I use Jdeveloper 11.1.1.3.0 version.

    I create object entity based on the table of the database that have primary keys.
    I created the view on this entity object. I created an array of viewobject, with CreatInsert button and my primary key in the table may while the new record is added.

    Now my problem is that I have created several rows by pressing CreateInsert Button several rows of time are created and displayed in the table. I insert data in all columns of all rows when I click on the submit button (who have the Action "# {bindings.Commit.execute} ') will save data of any 1 line not all data line.

    How can I save all the lines that is created in a single transaction?

    Thanks in advance
    Amit

    Amit,

    I just tried this (all by default, no code written), and he recorded all of the lines. It must be something unique to your application. Michael asks a lot of questions.

    John

  • How to create an entity with more than one primary key.

    Hello

    JDeveloper Version 11.1.2.4.0

    I am trying to create an entity object based on a table with 5 columns. The combination of them is unique.

    I do the five columns of primary keys, but when I delete a line I: RowAlreadyDeletedException, although always the line exists in the database.

    Also displaying the view sometimes I get Houston-25019: line entity oracle.jbo.Key [1 key 2 null null NULL].



    How to create an entity based on one object several columns in the primary key?

    I don't want to add an additional column to a primary key, because this table is used in many PL/SQL procedures, and I'm not sure that this will not affect the.

    Also using Rowid as a primary key should be avoided.

    Kind regards

    Pamela.

    As I said, the framework is not like that

    Check this old (but still relevant) blog of Sung Im on Table Whose Primary Key entity object can be NULL

    describing the reason behind the behavior you're seeing and the way around.

    Or you use the secondary key rather as described here Wael Abdeen Blog, how to look at the views - part 2 | Oracle ADF as a secondary key composed of more then one column can have null values.

    Timo

  • Add new ID/Primary Key column with custom ID generation

    I use Hibernate as ORM to interact with Oracle.

    This issue is no longer on the side of SQL to emulate the generator ID seqHiLo

    that we use to generate the primary key for tables, the column ID i.e.

    Now I want to add a new column to the ID of an already created table, and this table has data.

    I have a procedure to add the ID column in a table:

    For example:

    ALTER table TableName add (columnName NUMBER);

    Then create the sequence

    CREATE SEQUENCE SEQ_ID

    START WITH 1

    INCREMENT BY 1

    MAXVALUE 99999999

    MINVALUE 1

    NOCYCLE;

    and after that he use the UPDATE statement to insert some values into the column like this

    UPDATE tableName SET columnName is seq_test_id. NEXTVAL

    Here I intend to use hibernate_sequence, to be in harmony with the hibernation of generation mode the ID's

    The question is:

    UPDATE tableName SET columnName = hibernate_sequence. NEXTVAL, generates the ID in the order.

    However, I need identifiers according to the algorithm of seqHiLo.

    Is there a way to do this in pure SQL?

    In short, can we have a personalized way to generate IDS to use in the new column, rather than a sequential,

    as stated above?

    If you update every row of a session, it won't make any difference if you select from a sequence and use this value immediately (as in your example) or if you go through the algorithm of HiLo: be it you will end up with sequentially numbered lines without leaving space. Then after the update block of existing lines, you will need to create the sequence to be used by your Hibernate application with an initial value of your current value divided by the low value.

    If you really want to implement the algorithm of HiLo for the bulk loading, you can of course do so. But it is not necessary: the effect will be the same.

  • With custom auto-generated primary key value

    How to implement the the custom generated automatically Coordinated as 'ISSUE00001', 'ISSUE00002' ADF entity object.

    Hello
    your PK should be varchar2 if you use oracle DB or what?
    While you use to generate the PK value you expect, you can use the database for him.
    http://www.exploreoracle.com/2010/10/11/sequence-number-for-primary-key-in-Oracle-ADF-JDeveloper/
    in this site, call your function in the dodml method. without using the sequence.
    If (operation == DML_INSERT) {}
    inside to call your function that allows to generate number with the string value. (u concat/join 'FROM' value for your build number max)

    }

    Thks.

Maybe you are looking for

  • G6-1d98dx: driver SM Bus HP Pavilion g6-1d98dx

    Hello My hard drive failed and I had to buy a new one and install W7 from scratch. I installed all the drivers from the support site, but the SM bus driver is not installed. Any help with this would be appreciated. Thank you.

  • All-in-one HP Officejet 5610: 'solutions HP' icon does not open

    Cannot scan. When I click on the HP solutions icon is no longer open to access scanning. I tried to disable the firewall and no difference. I tried to disable the antivirus software. no difference. I've uninstalled and reinstalled the software; no di

  • Viewer.exe stopped work and why is it happening?

    App crashes/viewer.exe has stopped working message appears

  • Problem loading blackBerry Smartphones?

    Hey I was wondering if someone could help me out, I never ran my battery completely died before so I do not know myself. When I plugged my blackberry to the wall charger to charge, the led will be red light for a few seconds then turns off, then it t

  • Pavilion a6230n Vista Recovery

    Impossible to find on the site of HP recovery disks I guess that they are not available. Vista sticker with the always readable product codes. My question is: Can I buy a copy of "system builder" of Win 7 and use the info on the Vista sticker to acti