Page 477 - Computer_Science_F5
P. 477

Computer Science  SQL commands                Example  context:  “If a table  needs to
                                                     store people’s names and their ages, you
           There are five fundamental command
                                                     would use  VARCHAR for  names  and
           categories, in SQL language, a standard
                                                     INT for ages.”
           language for managing and manipulating
           databases. These command categories
          FOR ONLINE READING ONLY
           are Data Definition Language (DDL)
           commands, Data Manipulation Language      Data  Definition  Language  (DDL)
                                                     commands
           (DML) commands, Data Query Language
           (DQL), Data Control Language (DCL)        DDL commands change the database’s
           and  Transaction Control  Language        structure, for example, by creating a table,
           (TCL). It is crucial to keep the following   deleting a table, and altering a table. DDL
           considerations in mind before diving into   has the following commands: CREATE,
           SQL:                                      ALTER, DROP, and TRUNCATE.
             (a) SQL statement starts with SQL       (a) CREATE
                command and ends with a semicolon
                (;);                                 The CREATE command is used to create
             (b) SQL statements are case insensitive,   a new database or table in the database.
                                                     It  has  the  following  syntax:  CREATE
                which means they can be written      DATABASE database_name;  for the
                using upper, lower, or mixed cases.   database  and CREATE  TABLE table_
                But it is a common practice to write   name (column_name datatypes [,]); for
                out SQL keyword commands in all      the table. The database must be created
                upper cases;                         first then, followed by the tables;
             (c) Using SQL, you can perform most
                of the actions in a database; and     Example:
             (d) SQL data types are critical because   CREATE DATABASE student;
                they tell the database what type of   CREATE TABLE student_registration (
                data to expect. Common data types     StudentID int,
                include:                              FirstName varchar (255),
                (i)  INT: An integer number.          MiddleName varchar (255),
                (ii)  VARCHAR:         Variable-      LastName varchar (255),
                    length strings. For example,      Address varchar (255)
                    VARCHAR(255) can store            );
                    strings up to 255 characters.    To create a database and table resulting
                (iii) TEXT: For long texts.          from this example,  select  SQL to
                (iv) DATE/TIME: For dates and        continue  with  the  code  and  type  the
                    times.                           code; first, you need to create a database
                (v)  FLOAT/DOUBLE: For floating-     and then the table as indicated in Figure
                    point numbers.                   8.19 this is because the table shall belong
                                                     to the database.

                                                 468
                                                                for Advanced Secondary Schools



     Computer Science Form 5.indd   468                                                     23/07/2024   12:34
   472   473   474   475   476   477   478   479   480   481   482