What you want to see on DotNetFunda.com ?
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 9600 |  Welcome, Guest!   Register  Login
 Home > Forums > Sql Server > how to create tcl command and dcl command in sql server 2005 with example ...
Venky.Net

how to create tcl command and dcl command in sql server 2005 with example

Replies: 1 | Posted by: Venky.Net on 4/30/2012 | Category: Sql Server Forums | Views: 947 | Status: [Member] | Points: 10  


hi
i am trying create tcl commands and dcl command but i can't create.anyone please give me answer with example


Reply | Reply with attachment | Alert Moderator

 Responses below this adGet hundreds of .NET Tips and Tricks videos

 Replies

Funda
Funda  
Posted on: 4/30/2012 11:34:04 AM
Level: Starter | Status: [Member] | Points: 25

DCL

GRANT - Gives user's access privileges to database
REVOKE - Withdraws user's access privileges to database given with the GRANT command
DCL COMMANDS
1)
GRANT SELECT, INSERT, UPDATE, DELETE ON album, song TO Elvis WITH ADMIN OPTION

The database may be accessed by a wide public, grant them only the SELECT statement.
REVOKE INSERT, UPDATE, DELETE ON album, song TO PUBLIC

2)
Create a group of users, which can add and modify records, but not delete them.
CREATE ROLE editors

GRANT SELECT, INSERT UPDATE ON album, song TO editors

3) You have got new guy in your team and you want to authorize him to delete records. His user name is JBlack
 GRANT editors, DELETE ON album, song TO JBlack

4) Once again you are alone to maintain the CD catalog, because all your co-workers are gone. Only the editors role is left and useless. Delete it.
 DROP ROLE editors



TCL
COMMIT - Saves work done in transactions
ROLLBACK - Restores database to original state since the last COMMIT command in transactions
SAVE TRANSACTION - Sets a savepoint within a transaction



USE tempdb;
GO
CREATE TABLE ValueTable ([value] int;)
GO

DECLARE @TransactionName varchar(20) = 'Transaction1';

--The following statements start a named transaction,
--insert two rows, and then roll back
--the transaction named in the variable @TransactionName.
--Another statement outside of the named transaction inserts two rows.
--The query returns the results of the previous statements.

BEGIN TRAN @TransactionName
INSERT INTO ValueTable VALUES(1), (2);
ROLLBACK TRAN @TransactionName;

INSERT INTO ValueTable VALUES(3),(4);

SELECT [value] FROM ValueTable;

DROP TABLE ValueTable;


--Results
--value
-------------
--3
--4

Please be specific ?.
Mark this as answered if it is useful

Venky.Net, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Reply - Please login to reply


Click here to login & reply

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/23/2013 12:26:11 PM