Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 217
  • Last Modified:

Data to new table

I have
Table1  T1Id, T2Id,  T1Text, T1Password,T3Id
Table2  T2Id, T2Text.
I add another table i.e. empty table.
Table3   T3Id, T3Text,Password
I want to create a new row in Table3 for each row in Table1.
I want to update the column T3Id in Table1 with the T3Id of the new row in Table3.
I want also to set Table3.Password=Table1.T1Password and Table3.T3Text=Table1.T1Text
How is best to do this?
0
johnkainn
Asked:
johnkainn
4 Solutions
 
Reza RadCommented:
is the T3Id as identity field?
is there any other unique key in table3 ?


0
 
vinurajrCommented:
Insert the Required data in Table3
Hope T3Id is a auto generating..?
then Update the data in Table1 with Table3

0
 
waltersnowslinarnoldCommented:
Create a Stored Procedure,

CREATE PROC usp_ProcedureName
AS

INSERT INTO Table3 (T3Text, Password) (SELECT T1Text, T1Password FROM Table1)
DECLARE @id INT
SET @id = SELECT TOP 1 T3Id FROM Table3 ORDER BY DESC
UPDATE Table1
SET T3Id = @id
WHERE T1Password IN (SELECT Password FROM Table3)
go
0
 
David L. HansenProgrammer AnalystCommented:
You could create a trigger to do this after you've created Table3.

See:
http://www.sqlteam.com/article/an-introduction-to-triggers-part-i
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now