I'm new to C# I would like insert data with subselect into my SQL Server database, I need help to write the script in C# for the following script in SQL Server.
I have two tables, products
and category
and a temporary table Mytemp
:
CREATE TABLE MyTemp(ID int)
INSERT INTO products (productName, price)
OUTPUT inserted.ID_ProductName
INTO MyTemp
VALUES ('Orange', '2')
INSERT INTO category (ID_productName, Category, Description)
VALUES
((SELECT ID FROM MyTemp), 'Fruits', 'DryFruits');
DROP TABLE MyTemp
You don't need a temp table for this, you can just do it this way:
INSERT INTO products (productName, price)
VALUES ('Orange', '2');
INSERT INTO category (ID_productName, Category, [Description])
VALUES (@@IDENTITY, 'Fruits', 'DryFruits');
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.