Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 how to prevent row is deleted?

Author  Topic 

wkm1925
Posting Yak Master

207 Posts

Posted - 2011-08-15 : 00:36:19
I've table and data as following,

CREATE TABLE [dbo].[acctInfo](
[idx] [int] IDENTITY(1,1) NOT NULL,
[myID] [varchar](20) NOT NULL,
[pwd] [varchar](100) NOT NULL,
[fullNme] [varchar](50) NOT NULL,
[daerahKutipan] [int] NOT NULL,
[allowReceiptBackDated] [bit] NULL,
[allowCheckedByOnOffcReceiptManagement] [bit] NULL,
[acctStat] [int] NOT NULL,
[crtBy] [varchar](20) NULL,
[crtDte] [datetime] NULL,
[updBy] [varchar](20) NULL,
[updDte] [datetime] NULL,
CONSTRAINT [PK_acctInfo] PRIMARY KEY CLUSTERED
(
[idx] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
CONSTRAINT [acctInfo_UQ1] UNIQUE NONCLUSTERED
(
[myID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO


SET IDENTITY_INSERT [dbo].[acctInfo] ON
INSERT [dbo].[acctInfo] ([idx], [myID], [pwd], [fullNme], [daerahKutipan], [allowReceiptBackDated], [allowCheckedByOnOffcReceiptManagement], [acctStat], [crtBy], [crtDte], [updBy], [updDte])
VALUES (1, N'sysownr', N'1925', N'Mohd Zailani Yunus', 1, 1, 1, 1, N'sysowner',
CAST(0x00009F2C00000000 AS DateTime), N'sysowner', CAST(0x00009F2C00000000 AS DateTime))
SET IDENTITY_INSERT [dbo].[acctInfo] OFF


sysownr is a root account. how to prevent sysownr to be deleted by the database user?

if possibe, please let me know.

if can't, please let me know the other way

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-08-15 : 00:45:47
Add a DELETE trigger which checks for this condition and rolls it back when this is being attempted.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

wkm1925
Posting Yak Master

207 Posts

Posted - 2011-08-15 : 00:53:50
tq sir. will try
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-08-15 : 00:54:13
You're welcome, glad to help.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

wkm1925
Posting Yak Master

207 Posts

Posted - 2011-08-15 : 00:57:05
i'm confuse, the trigger is before or after?
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-08-15 : 01:01:17
SQL Server only have AFTER and INSTEAD OF trigger.

For your requirement, you may use AFTER TRIGGER.


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-08-15 : 01:03:15
It would be a normal after trigger.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

wkm1925
Posting Yak Master

207 Posts

Posted - 2011-08-15 : 01:22:44
I can't imagine how my trigger looks like
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-08-15 : 01:36:59
IF EXISTS (SELECT * FROM deleted WHERE myID = 'sysownr')
ROLLBACK TRAN

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

wkm1925
Posting Yak Master

207 Posts

Posted - 2011-08-15 : 02:04:41
tq sir
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-08-15 : 11:19:13
You're welcome, glad to help.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -