Hi guys, I'd like to create an INSTEAD OF trigger for the Person.Address table in AdventureWorks so that anytime someone inserts a value that does not begin with a number in AddressLine1 column, it returns a message "Invalid, value must contain numbers".
Can someone please write the code for this? thanks.
This is what I managed to write but it's still accepting addresses without numbers in AddressLine1 column, what did I do wrong?
CREATE TRIGGER trg_PersonAddress_AfterInsert ON Person.Address INSTEAD OF INSERT AS BEGIN IF EXISTS (SELECT AddressLine1 FROM Person.Address WHERE AddressLine1 LIKE '[0-9]%') INSERT INTO Person.[Address] (AddressID,AddressLine1,AddressLine2,City,StateProvinceID,PostalCode,SpatialLocation,rowguid,ModifiedDate) SELECT AddressID,AddressLine1,AddressLine2,City,StateProvinceID,PostalCode,SpatialLocation,rowguid,ModifiedDate FROM inserted ELSE PRINT 'Invalid must contain numbers' END;