Restrict access in SQL server I am using SQL server. I have a view (VIEW1) in DB1.

Now, I have created another (VIEW2) in DB2:

Create VIEW2 as Select * from DB1.VIEW1 where id not in (select ID from DB2.Table2)


I want a user to be able to select from DB2.VIEW2, but not from DB1.VIEW1 directly.

In other words, this would work:

SELECT * FROM DB2.VIEW2


and this would not:

SELECT * FROM DB1.VIEW1


Is it possible? If yes how?
Since your view2 selects from view1 in another database, as it configured now the permissions on view1 will be checked, so if you just do 

DENY SELECT ON [dbo].[ViewName] TO [UserWithoutAccess]


your select from view2 will fail with 


  The SELECT permission was denied on view1, schema dbo, database db1.


What you should do is to enable your databases to cross-db chaining:
Enabling Cross-Database Access in SQL Server

i.e. execute this in both databases:

ALTER DATABASE db1 SET DB_CHAINING ON;  
ALTER DATABASE db2 SET DB_CHAINING ON; 


This way ownership chain will not be broken when you pass to another database and the permissions on view1 will not be checked.

Database owners of db1, db2 should be the same.

More on ownership chaining here: Ownership Chains