ประเภทคอลัมน์และข้อจำกัด

Exploratory Data Analysis ใน SQL

Christina Maimone

Data Scientist

ข้อจำกัดของคอลัมน์

  • Foreign key: ค่าต้องมีอยู่ในคอลัมน์ที่อ้างอิง หรือเป็น NULL
  • Primary key: ไม่ซ้ำกัน และไม่เป็น NULL

  • Unique: ค่าต้องไม่ซ้ำกัน ยกเว้น NULL

  • Not null: ไม่อนุญาตให้เป็น NULL ต้องมีค่าเสมอ

  • Check constraints: กำหนดเงื่อนไขสำหรับค่าในคอลัมน์

    • column1 > 0
    • columnA > columnB
Exploratory Data Analysis ใน SQL

ประเภทข้อมูล

ทั่วไป

  • Numeric
  • Character
  • Date/Time
  • Boolean

พิเศษ

  • Arrays
  • Monetary
  • Binary
  • Geometric
  • Network Address
  • XML
  • JSON
  • และอื่น ๆ อีกมาก!
Exploratory Data Analysis ใน SQL

ประเภทตัวเลข: เอกสาร PostgreSQL

ตารางชื่อและคำอธิบายประเภทข้อมูลตัวเลข

Exploratory Data Analysis ใน SQL

ประเภทข้อมูลใน Entity Relationship Diagram

ตารางฐานข้อมูล Fortune 500

Exploratory Data Analysis ใน SQL

การแปลงประเภทด้วย CAST()

รูปแบบ

-- With the CAST function
SELECT CAST (value AS new_type);

ตัวอย่าง

-- Cast 3.7 as an integer
SELECT CAST (3.7 AS integer);
4
-- Cast a column called total as an integer
SELECT CAST (total AS integer)
  FROM prices;
Exploratory Data Analysis ใน SQL

การแปลงประเภทด้วย ::

รูปแบบ

-- With :: notation
SELECT value::new_type;

ตัวอย่าง

-- Cast 3.7 as an integer
SELECT 3.7::integer;
-- Cast a column called total as an integer
SELECT total::integer
  FROM prices;
Exploratory Data Analysis ใน SQL

มาฝึกกันเถอะ!

Exploratory Data Analysis ใน SQL

Preparing Video For Download...