So I want to insert data from tableA to tableB depending on their pvkey. Each row has his pvkey and one row under the same pvkey can have several records and each of these records has his unique cnkey. Cnkey is unique for any data in table. When I am inserting data from tableA there is no column Cnkey and in tableB there is Cnkey.
INSERT INTO CONTHIST (CONTTYPE, ASSIGNEDTO, CONTDATE, SOURCE, CNKEY)
SELECT ContactType, ASSIGNEDTO, DATE, SourceCode, ?!?!
FROM MopUpEOC
WHERE Pvkey in (1,5,7,9,11,20)
Can you help me with this, thank you :D
A few things that could help you:
CnKey
is the serial primary key of your table. If it is the serial primary key, you have no problem. CnKey
is NOT NULL
, if not, you can change it's value later, or you can set a default value. For example, the column CnKey
is NOT NULL
, then you can use following Query to allow NULL
:
ALTER TABLE TableB ALTER COLUMN CnKey INT NULL
Change INT
to the real type of your column.
Or you set a Default Value:
ALTER TABLE TableB ADD CONSTRAINT ConstraintName DEFAULT 'DefaultName' FOR CnKey;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.