0

I want to use as primary key, the primary key of another table just when a condition is true.

Example

TBL1 has PK identity IdTest and two columns Nome Varchar and HasValue Boolean

For all the HasValue True I want to create this other table TBL2 that will have IdTest as PK not identity (that is the same as TBL1) and a column Note Varchar.

Please help me as soon as u can

Ervina Rucaj
  • 35
  • 1
  • 8
  • Found solution : http://stackoverflow.com/questions/20963961/sql-server-stored-procedure-to-insert-in-multiple-tables – Ervina Rucaj Dec 04 '15 at 11:39

1 Answers1

0

Create the table first

CREATE TABLE TBL2 (
                   IDTest INT NOT NULL PRIMARY KEY
                  ,Nome Varchar(100)
                  )
GO

Populate the data

INSERT INTO TBL2 (IDTest, Nome)
SELECT IDTest, Nome
FROM TBL1
WHERE HasValue = 1
M.Ali
  • 67,945
  • 13
  • 101
  • 127