0
0
SQLquery~5 mins

Tables, rows, and columns concept in SQL

Choose your learning style9 modes available
Introduction

Tables organize data in a simple way using rows and columns. This helps us store and find information easily.

When you want to save a list of customers with their details.
When you need to keep track of products and their prices.
When you want to record daily sales data.
When you want to organize employee information like names and job titles.
Syntax
SQL
CREATE TABLE table_name (
  column1 datatype,
  column2 datatype,
  column3 datatype
);
A table is like a spreadsheet with rows and columns.
Each row is one record or entry.
Each column holds one type of information, like a name or number.
Examples
This creates a table named Customers with three columns: an ID number, a name, and a city.
SQL
CREATE TABLE Customers (
  CustomerID INT,
  CustomerName VARCHAR(100),
  City VARCHAR(50)
);
This table stores product details including an ID, name, and price with two decimal places.
SQL
CREATE TABLE Products (
  ProductID INT,
  ProductName VARCHAR(100),
  Price DECIMAL(10,2)
);
Sample Program

This example creates an Employees table, adds two employees, and then shows all the data in the table.

SQL
CREATE TABLE Employees (
  EmployeeID INT,
  FirstName VARCHAR(50),
  LastName VARCHAR(50),
  JobTitle VARCHAR(50)
);

INSERT INTO Employees VALUES (1, 'Alice', 'Smith', 'Manager');
INSERT INTO Employees VALUES (2, 'Bob', 'Brown', 'Sales');

SELECT * FROM Employees;
OutputSuccess
Important Notes

Each row must have a value for every column unless the column allows empty values.

Column names should be clear to understand what data they hold.

Summary

Tables store data in rows and columns.

Rows are individual records.

Columns define the type of data stored.