Use with clause or CTE or Common type expression in Sql Server

CTE in SQL server is the result set like table.

e.g.
WITH Sales_CTE (SalesPersonID, NumberOfOrders)
AS
(
SELECT SalesPersonID, COUNT(*)
FROM Sales.SalesOrderHeader
WHERE SalesPersonID IS NOT NULL
GROUP BY SalesPersonID
)
SELECT AVG(NumberOfOrders) AS “Average Sales Per Person”
FROM Sales_CTE;
GO

The DELETE statement conflicted with the REFERENCE constraint in SQL server

You have two real choices here, you can disable constraints on the table. This usually not a great idea as you can end up with a bad data condition if you’re messing with data that relates to other tables, but not know the full extent of your schema and it may suit your purposes:
ALTER TABLE [tablename] NOCHECK CONSTRAINT [FK_idconstraint]
Remember to turn the constraint back on after the delete with
ALTER TABLE [tablename] WITH CHECK CHECK CONSTRAINT [FK_idconstraint]
The second choice would be to drop and re-add the constraint with the ON DELETE CASCADE option using:
ALTER TABLE [tablename] DROP CONSTRAINT [FK_idconstraint]

ALTER TABLE [tablename] WITH NOCHECK ADD CONSTRAINT [FK_idconstraint] FOREIGN KEY(columnname)
REFERENCES <parent table here> (<parent column here>)
ON DELETE CASCADE