Previous Topic

Next Topic

Examples: Insert

The following are Insert statement examples:

  1. Add a row to an existing table.

    insert into emp (name, sal, bdate)
        values ('Jones, Bill', 10000, 1944);

  2. Insert all rows from the newjob table where the job title is not janitor into the job table insert into job (jid, jtitle, lowsal, highsal).

    select job_no, title, lowsal, highsal
    from newjob
    where title <> 'Janitor';

  3. Add a row to an existing table, using the default columns.

    insert into emp
        values ('Jones, Bill', 10000, 1944);

  4. Use a structure to insert a row.

    /* Description of table employees from
        database deptdb */

    exec sql declare employees table
       (eno           smallint not null,
        ename         char(20) not null,
        age           smallint,
        jobcode       smallint,
        sal           float not null,
        deptno        smallint);

    exec sql begin declare section;

        emprec
            int           eno;
            char          ename[21];
            int           age;
            int           job;
            float         sal;
            int           deptno;

    exec sql end declare section;

      /* Assign values to fields in structure */

      eno = 99;

      ename = "Arnold K. Arol";

      age = 42;

      jobcode = 100;

      sal = 100000;

      deptno=47;

      exec sql connect deptdb;

      exec sql insert into employees values (:emprec);

      exec sql disconnect;


© 2007 Ingres Corporation. All rights reserved.