Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- BEGIN TRANSACTION
- DECLARE @DataID int
- INSERT INTO DataTable (Column1 ...) VALUES (....)
- SELECT @DataID = scope_identity()
- INSERT INTO LinkTable VALUES (@ObjectID, @DataID)
- COMMIT
- DECLARE @Object_Table TABLE
- (
- Id INT NOT NULL PRIMARY KEY
- )
- DECLARE @Link_Table TABLE
- (
- ObjectId INT NOT NULL,
- DataId INT NOT NULL
- )
- DECLARE @Data_Table TABLE
- (
- Id INT NOT NULL Identity(1,1),
- Data VARCHAR(50) NOT NULL
- )
- -- create two objects '1' and '2'
- INSERT INTO @Object_Table (Id) VALUES (1)
- INSERT INTO @Object_Table (Id) VALUES (2)
- -- create some data
- INSERT INTO @Data_Table (Data) VALUES ('Data One')
- INSERT INTO @Data_Table (Data) VALUES ('Data Two')
- -- link all data to first object
- INSERT INTO @Link_Table (ObjectId, DataId)
- SELECT Objects.Id, Data.Id
- FROM @Object_Table AS Objects, @Data_Table AS Data
- WHERE Objects.Id = 1
- -- now I want to copy the data from from object 1 to object 2 without looping
- INSERT INTO @Data_Table (Data)
- OUTPUT 2, INSERTED.Id INTO @Link_Table (ObjectId, DataId)
- SELECT Data.Data
- FROM @Data_Table AS Data INNER JOIN @Link_Table AS Link ON Data.Id = Link.DataId
- INNER JOIN @Object_Table AS Objects ON Link.ObjectId = Objects.Id
- WHERE Objects.Id = 1
- $qry = "INSERT INTO table (one, two, three) VALUES('$one','$two','$three')";
- $result = @mysql_query($qry);
- $qry2 = "INSERT INTO table2 (one,two, three) VVALUES('$one','$two','$three')";
- $result = @mysql_query($qry2);
- $qry = "INSERT INTO table (one, two, three) VALUES('$one','$two','$three')";
- $result = @mysql_query($qry);
- $qry2 = "INSERT INTO table2 (two) VALUES('$two')";
- $result = @mysql_query($qry2);
- "$qry"-number and number in @mysql_query($qry"")
Add Comment
Please, Sign In to add comment