0

I want to create a view from a table student and want to add an extra column. does this view take space at disk/file on adding extra column? here is my code:

CREATE OR REPLACE VIEW DETAILS
AS SELECT Name, Serial_number,NULL AS 'additional_field1' from student;
Bill Karwin
  • 538,548
  • 86
  • 673
  • 828

1 Answers1

2

MySQL views never take any space, except for the metadata, that is the definition of the view itself.

They don't store any data, they are more like a macro. When you query the view, it actually runs the query in the view definition.

Bill Karwin
  • 538,548
  • 86
  • 673
  • 828
  • thanks for your response. then where data of the extra column will store. – Priya singh Apr 02 '21 at 04:30
  • 1
    A constant expression in a select-list is not stored anywhere. You can run a query like `SELECT NOW();` or `SELECT 'my string';` and these values are only created in the result set of a query. They are not stored. This is true of any query, not only when using a view. – Bill Karwin Apr 02 '21 at 04:38
  • what if I am creating a view only by adding columns, which are not present in the table? I mean without selecting columns of table. – Priya singh Apr 02 '21 at 04:52
  • 1
    Tell me, does a recipe need to be refrigerated? No, because a recipe is not actually food. It only describes the steps to prepare a specific dish. Does a roadmap require petrol? No, because a map describes a route, but it isn't a motor vehicle. Similarly, a view does not actually store any data. It only defines a query. – Bill Karwin Apr 02 '21 at 05:41