SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


locking table


locking table

Author
Message
sekannak
sekannak
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
Points: 4 Visits: 39
Hi,
I have a table - how to lock my table not to INSERT/UPDATE/DELETE plz answer me...


regards,
kannak.....
ps.
ps.
Hall of Fame
Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)

Group: General Forum Members
Points: 3265 Visits: 3668
sekannak (9/5/2009)

Hi,
I have a table - how to lock my table not to INSERT/UPDATE/DELETE plz answer me...


regards,
kannak.....


One way that i can think of doing this is put this table in a read only filegroup which will prevent insert/update/delete operation on the table.



Pradeep Singh
ps.
ps.
Hall of Fame
Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)

Group: General Forum Members
Points: 3265 Visits: 3668
The other way is to create a insert/update/delete trigger that roll backs any modification to the base table, however i still prefer the previous method of putting the table in a read only filegroup..



Pradeep Singh
Marcin Gol
Marcin Gol
Old Hand
Old Hand (324 reputation)Old Hand (324 reputation)Old Hand (324 reputation)Old Hand (324 reputation)Old Hand (324 reputation)Old Hand (324 reputation)Old Hand (324 reputation)Old Hand (324 reputation)

Group: General Forum Members
Points: 324 Visits: 178
maybe you can use deny permission ?
Paul White
Paul White
SSCoach
SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)

Group: General Forum Members
Points: 15834 Visits: 11355
The following script illustrates one way to use a read-only file group.


-- Temporary database
CREATE DATABASE [6D79D4CD-D98F-4D75-B3C0-6134DF86BDC2];
GO
-- Add a file group to hold read-only tables
ALTER DATABASE [6D79D4CD-D98F-4D75-B3C0-6134DF86BDC2]
ADD FILEGROUP [FG_READ_ONLY];
GO
-- Add an NDF file to the filegroup
DECLARE @data_path NVARCHAR(256);
SET @data_path =
(
SELECT SUBSTRING(physical_name, 1, CHARINDEX(N'master.mdf', LOWER(physical_name)) - 1)
FROM master.sys.master_files
WHERE database_id = 1
AND [file_id] = 1
);
EXECUTE
(
'ALTER DATABASE [6D79D4CD-D98F-4D75-B3C0-6134DF86BDC2]
ADD FILE
(
NAME = F_Read_Only,
FILENAME = ''' + @data_path + 'F_Read_Only.NDF'',
SIZE = 64MB,
MAXSIZE = 64MB,
FILEGROWTH = 0MB
)
TO FILEGROUP [FG_READ_ONLY];'
);
-- Switch to the new database
USE [6D79D4CD-D98F-4D75-B3C0-6134DF86BDC2];
GO
-- Test table (read-write)
CREATE TABLE dbo.ExistingTable
(
col1 INTEGER IDENTITY
CONSTRAINT [PK dbo.ExistingTable col1]
PRIMARY KEY CLUSTERED
WITH (FILLFACTOR = 100)
ON [PRIMARY]
);
GO
-- Add some rows
INSERT dbo.ExistingTable DEFAULT VALUES;
INSERT dbo.ExistingTable DEFAULT VALUES;
INSERT dbo.ExistingTable DEFAULT VALUES;
GO
-- Show the data
SELECT *
FROM dbo.ExistingTable;
GO
-- Move the data to the new file group
ALTER TABLE dbo.ExistingTable
DROP CONSTRAINT [PK dbo.ExistingTable col1]
WITH (MOVE TO [FG_READ_ONLY]);
GO
-- Re-create the primary key
ALTER TABLE dbo.ExistingTable
ADD CONSTRAINT [PK dbo.ExistingTable col1]
PRIMARY KEY CLUSTERED (col1)
WITH (FILLFACTOR = 100)
ON [FG_READ_ONLY];
-- Now make the file group read only
ALTER DATABASE [6D79D4CD-D98F-4D75-B3C0-6134DF86BDC2]
MODIFY FILEGROUP [FG_READ_ONLY]
READ_ONLY;
-- Show the data
SELECT *
FROM dbo.ExistingTable;
GO
-- Modifications fail now with the message:
-- (The index ... resides on a read-only filegroup ("FG_READ_ONLY"), which cannot be modified.
INSERT dbo.ExistingTable DEFAULT VALUES;
GO
-- Tidy up
USE [master];
DROP DATABASE [6D79D4CD-D98F-4D75-B3C0-6134DF86BDC2];





Paul White
SQLPerformance.com
SQLblog.com
@SQL_Kiwi
ps.
ps.
Hall of Fame
Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)

Group: General Forum Members
Points: 3265 Visits: 3668
Very Neat and Tidy script Paul :-)



Pradeep Singh
Paul White
Paul White
SSCoach
SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)

Group: General Forum Members
Points: 15834 Visits: 11355
ps (9/6/2009)
Very Neat and Tidy script Paul :-)

Thank you Pradeep!

I had a few minutes spare and your read-only file group idea made me think of a few things which I wanted to demo in a script.
So thanks for the inspiration!

Paul



Paul White
SQLPerformance.com
SQLblog.com
@SQL_Kiwi
kumarabhi281
kumarabhi281
Forum Newbie
Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: General Forum Members
Points: 1 Visits: 5
hi this is abhi ,
simply write this sql query on your sql prompt:
connect scott/tiger
-- u must authorize as a sysdba:


lock table table_name in share mode;

u can also lock your table in exclusive mode.
raja.2012.raja
raja.2012.raja
Forum Newbie
Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: General Forum Members
Points: 2 Visits: 22
go to permissions on table properties then permissions then select user roles search button press then select public press ok then select grant what ever u want
GilaMonster
GilaMonster
SSC Guru
SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)

Group: General Forum Members
Points: 87945 Visits: 45274
Please note: 4 year old thread

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search