I need to insert data into 3 tables in a single query
Table SkillData
UserIndex | SkillPoint | TotalSkill |
---|---|---|
1 | 5202 | 99 |
Table Emblems
UserIndex | CountEmblem | Status |
---|---|---|
1 | 1265 | 1 |
Table Rewards
UserIndex | Level | Code |
---|---|---|
1 | 99 | 1005 |
If your reason is to save space in your PHP, you might can use a Stored Procedure for this. Example below:
CREATE PROCEDURE dbo.InsertUserStuff
@UserIndex INT,
@SkillPoint INT,
@TotalSkill INT,
@CountEmblem INT,
@Status INT,
@Level INT,
@Code INT
AS
BEGIN
SET XACT_ABORT ON;
BEGIN TRAN;
INSERT INTO dbo.SkillData
(
UserIndex,
SkillPoint,
TotalSkill
)
VALUES
(
@UserIndex,
@SkillPoint,
@TotalSkill
);
INSERT INTO dbo.Emblems
(
UserIndex,
CountEmblem,
Status
)
VALUES
(
@UserIndex,
@CountEmblem,
@Status
);
INSERT INTO dbo.Rewards
(
UserIndex,
Level,
Code
)
VALUES
(
@UserIndex,
@Level,
@Code
);
COMMIT TRAN;
END;
You can execute this query with:
EXEC dbo.InsertUserStuff
@UserIndex = 1,
@SkillPoint = 5202,
@TotalSkill = 99,
@CountEmblem = 1265,
@Status = 1,
@Level = 99,
@Code = 1005
Obviously you need to change the datatypes to whatever you are using.
INSERT
statements?