DEV Community

Cover image for πŸš€ Day 4: Mastering SQL πŸš€
Aniket Tiwari
Aniket Tiwari

Posted on

πŸš€ Day 4: Mastering SQL πŸš€

Today’s focus was on mastering the fundamentals of table creation and description in MySQL. Understanding these basics is crucial for efficiently managing and organizing data. Here’s a quick rundown:

πŸ“Œ Creating Tables in MySQL

The CREATE TABLE statement is used to create a new table in the database.

Syntax:

CREATE TABLE table_name (
    column1 datatype constraints,
    column2 datatype constraints,
    ...
);
Enter fullscreen mode Exit fullscreen mode

Example:

CREATE TABLE Employees (
    EmployeeID INT PRIMARY KEY,
    FirstName VARCHAR(50),
    LastName VARCHAR(50),
    BirthDate DATE,
    HireDate DATE,
    Salary DECIMAL(10, 2)
);
Enter fullscreen mode Exit fullscreen mode

πŸ“Œ Describing Tables in MySQL

The DESCRIBE statement provides a detailed structure of the table, including column names, data types, and constraints.

Syntax:

DESCRIBE table_name;
Enter fullscreen mode Exit fullscreen mode

Example:

DESCRIBE Employees;
Enter fullscreen mode Exit fullscreen mode

πŸ“Œ Common Data Types in MySQL

  • INT: Integer values.
  • VARCHAR(size): Variable-length string with a maximum length of size.
  • DATE: Date values in YYYY-MM-DD format.
  • DECIMAL(p, s): Fixed-point numbers where p is the precision (total number of digits) and s is the scale (number of digits after the decimal point).

🌟 Key Takeaways:

  • CREATE TABLE is foundational for database structure.
  • DESCRIBE helps understand the schema and verify table structures.
  • Knowing data types ensures the right kind of data storage and efficient querying.

Excited to dive deeper into SQL and explore more advanced concepts in the coming days! Stay tuned for more updates. πŸš€

Top comments (0)