I want to truncate multiple tables if the table has dependencies. I tried couple of solutions from StackOverflow
e.g. Solution 1 but seems not working.
The table structure is below:
CREATE TABLE AEvent (
eID int NOT NULL,
startTime datetime NOT NULL,
endTime datetime NULL,
CONSTRAINT PK_A_EVENT PRIMARY KEY NONCLUSTERED (eID)
);
CREATE TABLE AEParam (
eID int NOT NULL REFERENCES AEvent(eID),
name nvarchar (446) NOT NULL,
value nvarchar (2048) NULL,
CONSTRAINT PK_A_E_PARAM PRIMARY KEY NONCLUSTERED (eID, name)
);
I tried using below query to truncate but seems not working.
SELECT concat('TRUNCATE TABLE ', TABLE_NAME, ';')
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME in ('AEvent','AEParam')