You must Sign In to post a response.
  • Category: SQL Server

    How to find exact difference between View and Select Statement in SQL in SQL Server?


    Are you looking for information on View and Select Statement in SQL in SQL Server? Want to know how to find exact difference between View and Select Statement in SQL in SQL Server? Read this thread to learn more about View and Select Statement in SQL in SQL Server with examples.



    Dear Sir,
    I created table named tblEmployeeDetails as follows.

    CREATE TABLE tblEmployeedetails
    (
    EmployeeName varchar(50) NOT NULL,
    Gender char(1) NOT NULL
    )

    I inserted values into tblEmployeeDetails as follows.

    INSERT INTO tblEmployeeDetails
    (
    EmployeeName,
    Gender
    )
    VALUES
    (
    abcdef,
    M
    )


    INSERT INTO tblEmployeeDetails
    (
    EmployeeName,
    Gender
    )
    VALUES
    (
    abc,
    F
    )

    I created view named vw_EmployeeDetails as follows.

    CREATE VIEW vw_EmployeeDetails
    AS
    SELECT * FROM tblEmployeeDetails WHERE Gender = M

    I am Executing Select Query as follows.

    SELECT * FROM tblEmployeeDetails WHERE Gender = M

    I am getting result for above select query as follows.

    EmployeeName Gender
    abcdef M

    I am Executing vw_EmployeeDetails View as follows.

    SELECT * FROM vw_EmployeeDetails

    I am getting result as follows.

    EmployeeName Gender
    abcdef M

    I want to know the Exact Difference between View and Select Statement in SQL.

    I also want to know in which situation we go for View in SQL.

    Its Urgent.

    Send Me Immediately.

    Thanks In Advance.
  • #729709
    Hai Baboo,
    There are many differences between the View and Table.
    As you have executed few Sql statements for the table and view, both are giving the same results. But there is countable differences between the duo.
    1. View is the virtual table. It doesn't store any data.
    2. When we call the view by using the Select command,. the data comes from the table only as view can't store any data.
    3. When we drop the View, the original table will not have any affect but if we delete the table, records will be deleted with the structure and calling the view will throw error as the table doesn't exists.
    4. Creating the view and permanently storing to the database is having advantages as it will store the view in compiled format so when we call the view, it just needs to be executed so performance will increase.
    5. We can create the view by joining multiple tables and retrieve the data from multiple tables so easy to call by a single select statement.
    Hope it will be helpful to you.

    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com

  • #729722
    Hi,

    I tell you the difference between those 2 in real time.

    for ex I'm working DataBase "X", and i don't have a permission with "Y" database but i want to fetch "y" database table information for that purpose i just create one view in "x" database. And i just refer that view wherever required to use "y" database table.

    Defination: view is same structure of a table you can perform actions whatever you did using table.

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #730321
    Hi,

    [1] View is a Virtual Table,view its is occupy any data.

    [2] cannot delete table using view.

    [3] if drop the view it is not affect the orignal table

    [4] more number of tables inside a view.

    [5] insert ,update, delete statements cannot support view


    hope this will help


    regards
    sriram.r


  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.