官术网_书友最值得收藏!

The students table

Let us take a look at the following fields in the table and what work they perform:

Note

It is advised to use a character datatype for fields such as zip codes or SSNs. Though the data is going to be a number, integer datatypes are notorious for removing preceding zeroes, so if there is a zip code that starts with a zero, such as 06909, of an integer datatype, the zip code would end up in the column as 6909.

Now let us convert this table structure into executable SQL, to create our table, we will be using the CREATE DDL command, followed by TABLE and then append it with the table structure. In SQL, the column description is done by mentioning the column name first and then adding the datatype of the column. The STUDENTS table has multiple columns, and the column information has to be separated by a comma (,).

The students table

Now that the query has been executed, the students table has been created. To verify if the students table has been successfully built, and to view a list of existing tables that are in the current database, we can use the SHOW utility command and append that with TABLES:

The students table

We have successfully used the show tables; command SQL statement to retrieve a list of existing tables, and have verified that our students table exists in our course_registry database. Now, let us verify if our students table has the same table structure as we originally intended it to have. We will use the DESCRIBE utility command followed by the table name to understand the table structure:

Tip

The DESCRIBE and DESC commands can be used interchangeably, both the commands would need the table name to return their structure.

The students table

Now let us move on to the courses table, this table will house all the available courses for which a student can register. The courses table will contain a unique identifier for the course (course_id), the name of the course (course_name), and a brief description of the course (course_description).

The courses table

Let us now look at the fields and the type of values they are storing:

Now let us convert this table structure into executable SQL to create our courses table:

The courses table

Now that the query has been executed, let us run the SHOW TABLES command to verify if the courses table has been created:

The courses table

The output from the SHOW TABLES command returns the list of current tables, and the courses table is one of them. Now that we have built the students table and the courses table, let us build the bridge table that would hold the association between the two tables. This table would contain the data about the students who were enrolled to a particular course.

The students_courses table

Let us now look at the fields in this table and their respective values:

Now, let us convert this table structure into executable SQL, to create our courses table using the following command:

The students_courses table

Now that the query has been executed, let us run the SHOW TABLES command to verify if the courses table has been created:

The students_courses table

The output from the SHOW TABLES command returns the list of current tables, and the students_courses table is one of them.

主站蜘蛛池模板: 洛阳市| 汾西县| 兴国县| 漳浦县| 庆城县| 海林市| 吉首市| 且末县| 杭州市| 蕲春县| 临清市| 景德镇市| 涿鹿县| 依安县| 云霄县| 乌兰浩特市| 石泉县| 康平县| 延寿县| 行唐县| 正宁县| 梅州市| 鹰潭市| 靖江市| 历史| 丁青县| 郁南县| 遵义市| 永胜县| 普兰店市| 永修县| 普洱| 宁城县| 农安县| 耒阳市| 搜索| 南阳市| 靖边县| 句容市| 泸溪县| 留坝县|