Table in SQL
A table in SQL is a fundamental database object that stores data in rows and columns, similar to a spreadsheet.
? Key Concepts of a Table
Rows (records): Each row represents a single record or entry.
Columns (fields): Each column stores a specific attribute or piece of data.
Each column has a data type (e.g.,
INT,VARCHAR,DATE) defining the kind of data it holds.Tables are created and managed using SQL commands.
? Creating a Table
Basic syntax:
CREATE TABLE table_name ( column1 datatype [constraints], column2 datatype [constraints], ...);Example:
CREATE TABLE Employees ( EmployeeID INT PRIMARY KEY, FirstName VARCHAR(50) NOT NULL, LastName VARCHAR(50) NOT NULL, HireDate DATE, Salary DECIMAL(10, 2));? Common Operations on Tables
| Operation | SQL Command | Description |
|---|---|---|
| Create table | CREATE TABLE | Defines a new table |
| Insert data | INSERT INTO | Adds new rows |
| Update data | UPDATE | Modifies existing rows |
| Delete data | DELETE | Removes rows |
| Select data | SELECT | Retrieves data |
| Drop table | DROP TABLE | Deletes the entire table |
? Example: Insert and Select
INSERT INTO Employees (EmployeeID, FirstName, LastName, HireDate, Salary)VALUES (1, 'John', 'Doe', '2020-01-15', 60000);SELECT * FROM Employees;Summary
Tables are the core data structure in relational databases.
Defined by columns with specific data types.
Hold data as rows of values.
Managed using SQL DDL and DML commands.
If you want, I can help you design a specific table schema or write queries related to tables!