What is the use of the view in sql server?

Possible duplicate:
What's good to watch?

Hi, I doubt that such an opinion. where should we use and what is the use of representation. is there a good link for views. thank

+5
source share
3 answers

Please take a look at the View (database) Wikipedia article .

In short, Viewit can be used with a lot of SQL Server, it is an SQL standard.

A Viewcommonly used:

  • Present informational data on a different point of view;
  • To simplify access to information of a complex high-level database schema,
  • ( ) ( - ORM);
  • "" View.

, .

CREATE TABLE Vehicules (
    VId int IDENTITY(1, 1) PRIMARY KEY
    , VDescription nvarchar(20) NOT NULL
)

CREATE TABLE MotoredVehicules (
    MvId int IDENTITY(1, 1) PRIMARY KEY
    , MvVId int NOT NULL REFERENCES Vehicules (VId)
    , MvMake nvarchar(20) NOT NULL
)

CREATE TABLE MotorHP (
    MhpId int IDENTITY(1, 1) PRIMARY KEY
    , MhpMvId int NOT NULL REFERENCES MotoredVehicules (MvId)
    , MhpHP decimal(6, 2) NOT NULL
)

CREATE TABLE VehiculesWheels (
    VwId int IDENTITY(1, 1) PRIMARY KEY
    , VwVId int NOT NULL REFERENCES Vehicules (VId)
    , VwNumberOfWheels int NOT NULL
)

insert into Vehicules (VDescription) values (N'Bicycle')
GO
insert into Vehicules (VDescription) values (N'Motorcycle')
GO
insert into Vehicules (VDescription) values (N'Automobile')
GO
insert into Vehicules (VDescription) values (N'Yacht')
GO

-- Inserting the information about the vehicules that have a motor.
insert into MotoredVehicules (MvVId, MvMake) (
    select v.VId
            , N'Harley Davidson'
        from Vehicules as v
        where v.VDescription LIKE N'Motorcycle'
)
GO
insert into MotoredVehicules (MvVId, MvMake) (
    select v.VId
            , N'Sea-Ray'
        from Vehicules as v
        where v.VDescription LIKE N'Yacht'
)
GO
insert into MotoredVehicules (MvVId, MvMake) (
    select v.VId
            , N'Mercedes'
        from Vehicules as v
        where v.VDescription LIKE N'Automobile'
)
GO

-- Inserting motor HP for the motorized vehicules.
insert into MotorHP (MhpMvId, MhpHP) (
    select mv.MvId
            , 350
        from MotoredVehicules as mv
        where mv.MvMake LIKE N'Sea-Ray'
)
GO
insert into MotorHP (MhMvId, MhpHP) (
    select mv.MvId
            , 280
        from MotoredVehicules as mv
        where mv.MvMake LIKE N'Mercedes'
)
GO
insert into MotorHP (MhpMvId, MhpHP) (
    select mv.MvId
            , 930
        from MotoredVehicules as mv
        where mv.MvMake LIKE N'Harley Davidson'
)
GO

-- Inserting the number of wheels for wheeled vehicules.
insert into VehiculesWheels (VwVId, VwNumberOfWheels) (
    select v.VId
            , 2
        from Vehicules as v
        where v.VDescription IN (N'Bicycle', N'Motorcycle')
)
GO
insert into VehiculesWheels (VwVId, VwNumberOfWheels) (
    select v.VId
            , 4
        from Vehicules as v
        where v.VDescription LIKE N'Automobile'
)
GO

. , NULL . - . , , , , , . :

CREATE VIEW WheeledMotoredVehiculesView AS
    select v.VId
            , mv.MvMake
            , hp.MhpHP
            , vw.NumberOfWheels
            , v.VDescription
        from Vehicules as v
            left join MotoredVehicules as mv on mv.MvVId = v.VId
            left join MotorHP as hp on hp.MhpMvId on mv.MvId
            left join VehiculesWheels as vw on vw.VwVId = v.VId
GO

CREATE VIEW MotoredVehiculesView AS
    select v.VId
            , mv.MvMake
            , hp.MhpHP
            , v.VDescription
        from Vehicules as v
            left join MotoredVehicules as mv on mv.MvId = v.Id
            left join MotorHP as hp on hp.MhpMvId = mv.MvId
GO

CREATE VIEW WheeledVehicules AS
    select v.VId
            , vw.NumberOfWheels
            , v.VDescription
        from Vehicules as v
            left join VehiculesWheels vw on vw.VwVId = v.VId
GO

, , , , , :

select *
    from MotoredVehiculesView

.

: . .

, , -.

+11

. SQL Server.

, . table, . , . , , . .

+3

"", , .

, ( , ..), .

.

-, SQL (.. ).

Secondly, you can enhance the security of source tables for a specific user, allowing them to view data through views.

+3
source

All Articles