'Creating A Stored Procedure That Truncates A Table With Foreign Keys

I would like to make a stored procedure in SSMS that will truncate a table that has foreign keys. Here is what I have right now but when I pass a table with foreign keys through the procedure, it gives the error that it is being referenced by a foreign key restraint.

CREATE PROCEDURE [dbo].[TruncateTable] @databaseName varchar(50), @tableName varchar(50)
AS
DECLARE @SQL VARCHAR(2000)
SET @SQL='TRUNCATE TABLE ' + @databaseName + '..' + @tableName
EXEC (@SQL)

I found this website helpful but I am unsure how to implement it in my code.

https://sqlsolutionsgroup.com/truncate-tables-that-have-foreign-keys/



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source