MulaiMulai sekarang secara gratis

Mencegah penghapusan tabel

Fresh Fruit Delivery ingin mencegah karyawan regulernya menghapus tabel dari database.

Latihan ini adalah bagian dari kursus

Membangun dan Mengoptimalkan Trigger di SQL Server

Lihat Kursus

Petunjuk latihan

  • Buat pemicu baru, PreventTableDeletion, untuk mencegah penghapusan tabel.
  • Pemicu harus melakukan rollback pada pernyataan pemicu, sehingga penghapusan tidak terjadi.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

-- Add a trigger to disable the removal of tables
CREATE TRIGGER ___
ON DATABASE
FOR ___
AS
	RAISERROR ('You are not allowed to remove tables from this database.', 16, 1);
    -- Revert the statement that removes the table
    ___;
Edit dan Jalankan Kode