Insert Values

Database
Enthusiast

Insert Values

Hi,

I have a table called Table A which is empty. I need to add a value from one particular column from another table.

How do i insert this and what is the syntax? Can anyone help me out as i am new to this?

5 REPLIES

Re: Insert Values

insert into databasename.tablename (table A)  ( column1) 

select column1

from databasename.tablename ( table b) ;

Enthusiast

Re: Insert Values

Hi,

That fails..It says the first column in the Table A needs a value and caannot be NULL

Re: Insert Values

show your table a structure

Enthusiast

Re: Insert Values

CREATE SET TABLE T1

     (

      RECORD_ID DECIMAL(27,0) NOT NULL,

      DEGREE_ZIP VARCHAR(32) CHARACTER SET LATIN CASESPECIFIC NOT NULL,

      VERSION_ID VARCHAR(32) CHARACTER SET LATIN CASESPECIFIC NOT NULL,

      ZIP_CODE VARCHAR(10) CHARACTER SET LATIN CASESPECIFIC,

      PERIOD_NAME VARCHAR(32) CHARACTER SET LATIN CASESPECIFIC,

      OPEN_KEY VARCHAR(50) CHARACTER SET LATIN CASESPECIFIC,

      START_DATE TIMESTAMP(6),

      END_DATE TIMESTAMP(6)

      )

      CREATE SET TABLE T2

     (

      KEY_ID DECIMAL(27,0) NOT NULL,

      DEGREE_ZIP VARCHAR(32) CHARACTER SET LATIN CASESPECIFIC NOT NULL,

      VERSION_ID VARCHAR(32) CHARACTER SET LATIN CASESPECIFIC NOT NULL,

      ZIP_CODE VARCHAR(10) CHARACTER SET LATIN CASESPECIFIC,

      PERIOD_NAME VARCHAR(32) CHARACTER SET LATIN CASESPECIFIC,

      OPEN_KEY VARCHAR(50) CHARACTER SET LATIN CASESPECIFIC,

      START_DATE TIMESTAMP(6),

      END_DATE TIMESTAMP(6)

      )

I need to insert the value of ZIP_CODE  from Table T2 to T1

Re: Insert Values

Two tables looks same and you want to insert only zip_code alone from table t2 into t1. But table t1 contains not null columns.

If you try to do as what i said earlier it tries to keep nulls in all columns of table1 except zip_code.

So as per table1 definition u cant add a row with null values in record_id,degree_zip,version_id.

so try doing

insert into table1 ( record_id,degree_zip,version_id)

select key_id,degree_zip,version_id from table2;