S.no | Contents-topics |
---|---|
1 | What Are Tables in SQL |
2 | Creating a Table |
3 | Inserting Data into a Table |
4 | Querying Data from a Table |
5 | Modifying a Table Structure |
Tables in SQL are the core structure for storing data in a relational database. Think of them as spreadsheets with rows and columns, where each column has a specific data type (e.g., INT, VARCHAR) and each row represents a record. For example, a table named users might store names and ages, like "John, 25". Tables organize data efficiently, allowing you to query, update, or delete it using SQL commands.
To create a table in SQL, you use the CREATE TABLE command, defining columns and their data types. Let’s create a users table as an example:
Copy this SQL command:Copy
Run this in a database tool like MySQL Workbench or phpMyAdmin to create the table. Here, id auto-increments, name holds up to 50 characters, and age stores integers.
To add data, use the INSERT INTO command. Let’s add a user to the users table:
Copy this SQL command:Copy
Also read: SQL BASICS FOR BEGINNERS
Execute this to insert a record. The id auto-increments (e.g., 1), and 'John Doe', 25 is added as a row.
To retrieve data, use the SELECT command. Here’s how to fetch all users:
Copy this SQL query:Copy
Run this to see all rows, like id: 1, name: 'John Doe', age: 25. Use conditions (e.g., WHERE age > 20) for specific data.
Also read: Custom Route File in Vue js
To change a table, use ALTER TABLE. Let’s add an email column to users:
Copy this SQL command:Copy
Execute this to add the email column. Now, users can store emails up to 100 characters, enhancing its structure.
0 Comments (Please let us know your query)