Page 333 - IT 402 v2.0 class 10
P. 333

et us create a table named Student having StudentId  FirstName   astName  and Marks  fields in the following
            way:

              CRE AT E  T AB L E  Stu d ent
              (
                   Stu d entI D  I NT E G E R,
                   F ir stName CH AR( 3 0 ) ,
                   L astName CH AR( 3 0 ) ,
                   M ar k s I NT
              ) ;
            In the preceding code, you have noticed that a value 30 is given with the CHAR data type within the parenthesis as
            its size. The meaning of 30 is that you can store a string value upto 30 characters in the FirstName and LastName
            fields.  hether you store a single character or    characters  this field will occupy space re uired for    characters.
            If you store one character, 29 blank spaces will be inserted with the character.

               INSERTING RECORDS IN A TABLE


            After creating a table, you can insert records into it by using the INSERT command. The syntax to insert a
            record into a table is:
              I NSE RT  I NT O  tab le_ name
              V AL U E S ( ' v al_ colu mn1 ' ,  ' v al_ colu mn2 ' ,  ... ,  ' v al_ colu mnN' ) ;

            Let us insert the following records in the Student table:
                            StudentID           FirstName            LastName              Marks

                              10001         Amit                 Sharma                      450
                              10002         Divya                Kaushik                     480
                              10003         Aadarsh              Kumar                       475
            To insert above records, we use the following commands:

              I NSE RT  I NT O  Stu d ent V AL U E S ( 1 0 0 0 1 ,  ' Amit' ,  ' Shar ma' ,  4 5 0 ) ;
              I NSE RT  I NT O  Stu d ent V AL U E S ( 1 0 0 0 2 ,  ' D iv y a' ,  ' K au shik ' ,  4 5 0 ) ;
              I NSE RT  I NT O  Stu d ent V AL U E S ( 1 0 0 0 3 ,  ' Aad ar sh' ,  ' K u mar ' ,  4 5 0 ) ;

               RETRIEVING RECORDS FROM TABLE

             he S      command retrieves  ero or more rows from a table. It helps us to  oin information from different
            tables and filter specific information as per the re uired criteria.  he S      command is the most useful  M
            command. The ‘SELECT’ statement has many optional clauses which are as follows:
                    specifies the criteria according to which rows are retrieved.

              O        specifies an order   scending or  escending  to return the rows.
            The syntax to execute the SELECT queries:

              SE L E CT  *  F RO M  tab le_ name;
            To display all the data in the table:

              SE L E CT  *  F RO M  Stu d ent;





                                                                                   Introduction to MySQL       331
   328   329   330   331   332   333   334   335   336   337   338