Nasty SQL Idea

time to read 2 min | 233 words

If I ever catch someone actually doing it, there would be hell to pay, but here is a new level of nastiness in SQL:

 

CREATE TABLE Nasty( [text] nvarchar(500));

CREATE TRIGGER Very Nasty Trigger ON  NASTY INSTEAD OF INSERT

AS BEGIN
      Declare @stmt nvarchar(max)
      SET @stmt = (select [text] from INSERTED);
      exec sp executesql @stmt
END

 

Usage: INSERT INTO NASTY([TEXT]) VALUES('SELECT 56');

 

The result of this query is 56, but it can do pretty much anything it wants. I’ll post later with the nastier query. This one is just the start. I’m seeing something (not as advanced) too much right now.