Page 254 - PYTHON-12
P. 254

(c)  Inserting data into specific columns of a table:
                         Syntax for SQL INSERT is:

                        INSERT INTO <table_name>[(column1, column2, ... columnN)]
                                         values [(value1, value2,.... valueN)];

                         For example, to insert a record into the student table for the columns Rollno, Name and
                         Marks only, the SQL insert query is:

                        INSERT INTO student (Rollno, Name, Marks) values (4,”Radhika Gupta”,78);
                        The above statement shall insert the values for specific columns—Rollno , Name and
                         Marks respectively.

                   (d)  Inserting NULL values into a table: If a column in a row has no value or missing value,
                         then the column is said to be null or holding NULL value. Null value can be given to any
                         column other than being assigned as primary key or Not Null constraint. It is advisable
                         to use Null when the actual value is not defined or unavailable. NULL values are treated
                         differently from other values  as they represent missing unknown  data.  By default, a
                         column in a table can hold NULL values.
                        If a column in a table is optional, we can insert a new record or can modify an existing
                         tuple without adding values to this column. In other words, the values in every record for
                         this column/field shall be stored as NULL. We can insert NULL value into any column in
                         a table. It can be done by typing NULL without quotes.

                        Null  is  not equivalent  to 0,  i.e.,  NULL  ≠  0.  It  acts  as  a  placeholder  for  unknown  or
                         inapplicable values.
                         For example, INSERT INTO student(Rollno, Name, Gender, Marks, DOB)


                                      VALUES(12,‘Swati Mehra’, ‘F’, NULL, NULL);
                         After the execution of the above command, NULL value shall be inserted for the
                         fields Marks and DOB respectively.


                 CTM: Null means unavailable or undefined value. Any arithmetic expression containing a NULL always
                 evaluates to null.

               8. Modifying Data in a Table

               To modify data in a table or to make changes for some or all of the values in the existing records in
               a table, we use the UPDATE statement. The UPDATE command specifies the rows to be modified
               using the WHERE clause and the new data is written into the respective record using the SET
           Computer Science with Python–XII  12.24   UPDATE <table_name>
               keyword.
               Syntax for UPDATE:


                 SET <column1> = <value1>, <column2> = <value2>,…..

                 WHERE <condition>;
   249   250   251   252   253   254   255   256   257   258   259