Table & View

 Tables 


1. create a table

Create table command use to create new table in Database.

Ex :

CREATE TABLE employee_table(  

    id int NOT NULL AUTO_INCREMENT,  

    name varchar(45) NOT NULL,  

    age int NOT NULL,  

);  


2. Alter table

The ALTER statement is always used with "ADD", "DROP" and "MODIFY" commands according to the situation.


1. ADD : 

  • The ADD command is used to add the column definition of the table.


Ex :

ALTER TABLE employee_table(  

    ADD emp_Address varchar(255) NOT NULL;

);  


2. MODIFY : 

  • The MODIFY command is used to change the column definition of the table.


Ex :

ALTER TABLE employee_table(  

    MODIFY emp_Address varchar(50) NOT NULL;

);  


3. DROP column :

  • use delete table from database. 


Ex :

ALTER TABLE employee_table(  

    DROP emp_Address ;

);  



Views

  • A view is a database object that has no values.
  • Its contents are based on the base table. It contains rows and columns similar to the real table.
  • In MySQL, the View is a virtual table created by a query by joining one or more tables. 
  • It is operated similarly to the base table but does not contain any data of its own.


Post a Comment

Previous Post Next Post