C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » SQL Server »

Create Views with limited access


Posted Date: 02 Nov 2009      Posted By: Christopher      Member Level: Gold     Points: 1   Responses: 1



hi

I have create some views to provide limited data access for an application,

How to do this task?





Responses

Author: Lalji    02 Nov 2009Member Level: DiamondRating: 2 out of 52 out of 5     Points: 2

you can use this code sample script
USE AdventureWorks
GO

-- Create table for employees
CREATE TABLE Employees
(EmpCode VARCHAR(8) PRIMARY KEY, Name VARCHAR(50) NOT NULL,
Designation VARCHAR(50) NOT NULL, QualificationCode TINYINT,
Deleted BIT NOT NULL DEFAULT 0)
GO

-- Create look up table for employees qualification
CREATE TABLE Lib_Qualification
(QualificationCode TINYINT PRIMARY KEY, Qualification VARCHAR(20) NOT NULL)
GO

-- Add constraint to lib_qualification
ALTER TABLE dbo.Lib_Qualification ADD CONSTRAINT
FK_Lib_Qualification_Lib_Qualification FOREIGN KEY
( QualificationCode ) REFERENCES dbo.Lib_Qualification
( QualificationCode ) ON UPDATE NO ACTION
ON DELETE NO ACTION
GO

-- Add constraint to employees
ALTER TABLE dbo.EMPLOYEES ADD CONSTRAINT
FK_EMPLOYEES_Lib_Qualification FOREIGN KEY
( QualificationCode ) REFERENCES dbo.Lib_Qualification
( QualificationCode ) ON UPDATE NO ACTION
ON DELETE NO ACTION
GO

-- Insert data into lib_qualification table
Insert into lib_qualification VALUES (1, 'MS')
Insert into lib_qualification VALUES (2, 'MCS')
Insert into lib_qualification VALUES (3, 'BCS')
Insert into lib_qualification VALUES (4, 'MBA')
GO

-- Insert data into employees table
Insert into Employees VALUES ('405-21-1' ,'Emp1' ,'Designation1' ,1 ,0)
Insert into Employees VALUES ('527-54-7' ,'Emp2' ,'Designation2' ,2 ,0)
Insert into Employees VALUES ('685-44-2' ,'Emp3' ,'Designation3' ,1 ,0)
Insert into Employees VALUES ('044-21-3' ,'Emp4' ,'Designation4' ,3 ,0)
Insert into Employees VALUES ('142-21-9' ,'Emp5' ,'Designation5' ,2 ,0)
GO

-- Create view by two base tables
CREATE VIEW vw_EmpQualification
AS
SELECT EmpCode, Name, Designation, Qualification
FROM employees E inner join lib_qualification Q
ON E.qualificationCOde = Q.QualificationCode
WHERE deleted = 0
GO

Select * from vw_EmpQualification
GO

You will get complete info from this link
---------------------------------
http://www.mssqltips.com/tip.asp?tip=1804




Post Reply
You must Sign In to post a response.
Next : Linq
Previous : BackUp of a Databases as Easily
Return to Discussion Forum
Post New Message
Category: SQL Server

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use