Page 258 - PYTHON-12
P. 258

E. Removing a column:


               To remove or drop a column in a table, ALTER TABLE command is used.
               Syntax for removing a column:
               ALTER TABLE <table-name> DROP
               <column-name>;

               For example,
               ALTER TABLE student DROP (State);

               The above command will drop State column from the student table.
               Resultant table: student

                Rollno  Name               Gender     Marks        DOB        Mobile_no
                  1.    Raj Kumar             M         93    17-Nov-2000        NULL
                  2.    Deep Singh            M         98    22-Aug-1996        NULL
                  3.    Ankit Sharma          M         76    02-Feb-2000        NULL
                  4.    Radhika Gupta         F         78    03-Dec-1999        NULL
                  5.    Payal Goel            F         82    21-April-1998      NULL
                  6.    Diksha Sharma         F         80    17-Dec-1999        NULL
                  7.    Gurpreet Kaur         F         65    04-Jan-2000        NULL
                  8.    Akshay Dureja         M         90    05-May-1997        NULL
                  9.    Shreya Anand          F         70    08-Oct-1999        NULL
                  10.   Prateek Mittal        M         75    25-Dec-2000        NULL

               11. DROP TABLE Command

               Sometimes, we may need to physically remove a table which is not in use. DROP TABLE command
               is used to remove/delete a table permanently. It should be kept in mind that we cannot drop a table
               if it contains records. That is why all the rows of the table have to be deleted first and only then can
               the table be dropped. This command will completely destroy the table structure.
               Syntax for removing a table:
                 DROP TABLE <table-name>;

                 For example,

                 mysql>DROP TABLE student;

               This command will permanently remove the table student from the database school.

               12.14 SQL QUERY PROCESSING
           Computer Science with Python–XII  12.28 screen. Retrieving information from the tables is done mainly using the SELECT command. The
               After creating the database, the table is created and the data is stored in it. Now, it is time to
               perform query processing on the already-created tables  to retrieve and view the data  on the

               SQL SELECT statement is used to fetch data from one or more database tables. It is used to select
               rows and columns from a database/relation.
   253   254   255   256   257   258   259   260   261   262   263