Data Science Explorer

SQL Code Analysis 본문

SQL

SQL Code Analysis

grace21110 2023. 10. 6. 17:28
반응형

This SQL code creates a table named dataset2 in a MySQL database. Let's break down the code step by step:

CREATE TABLE `dataset2` (
  `Clothing ID` int DEFAULT NULL,
  `Age` int DEFAULT NULL,
  `Title` text,
  `Review Text` text,
  `Rating` int DEFAULT NULL,
  `Recommended IND` int DEFAULT NULL,
  `Positive Feedback Count` int DEFAULT NULL,
  `Division Name` text,
  `Department Name` text,
  `Class Name` text
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci

1. Table Name and Columns:

CREATE TABLE `dataset2` (
  • CREATE TABLE: This SQL statement is used to create a new table.
  • dataset2: This is the name of the table you are creating.

 

2. Column Definitions:

`Clothing ID` int DEFAULT NULL,
`Age` int DEFAULT NULL,
`Title` text,
`Review Text` text,
`Rating` int DEFAULT NULL,
`Recommended IND` int DEFAULT NULL,
`Positive Feedback Count` int DEFAULT NULL,
`Division Name` text,
`Department Name` text,
`Class Name` text
  • This section defines the columns that will exist in the dataset2 table, along with their data types and default values.
  • Each column is enclosed in backticks (`) to allow for the use of spaces in column names.
  • The columns and their definitions are as follows:
    • Clothing ID: An integer column with a default value of NULL.
    • Age: An integer column with a default value of NULL.
    • Title: A text column that can store variable-length text data.
    • Review Text: A text column for storing review text.
    • Rating: An integer column with a default value of NULL.
    • Recommended IND: An integer column with a default value of NULL.
    • Positive Feedback Count: An integer column with a default value of NULL.
    • Division Name: A text column.
    • Department Name: A text column.
    • Class Name: A text column.

 

3. Storage Engine and Character Set:

) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

This part specifies additional table properties:

  • ENGINE=InnoDB: It sets the storage engine for the table to InnoDB. InnoDB is a commonly used storage engine in MySQL known for its support for transactions and referential integrity.
  • DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci: It sets the character set and collation for the table. In this case, it's using the utf8mb4 character set, which is suitable for storing a wide range of characters, including emojis and special symbols. The collation utf8mb4_0900_ai_ci specifies a case-insensitive and accent-insensitive collation.

 

 

This code is referred a book called SQL로 맛보는 데이터 전처리 분석(노수영 저). 

https://product.kyobobook.co.kr/detail/S000001934242

'SQL' 카테고리의 다른 글

[Basic Grammar] SQL SELECT Statement  (0) 2023.10.12
SQL Code Analysis  (0) 2023.10.11
SQL Code Analysis  (0) 2023.10.10
SQL Code Analysis  (0) 2023.10.10
SQL Code Analysis  (0) 2023.10.06