0% found this document useful (0 votes)
3 views3 pages

Insert Data in SQL

The document explains how to insert and display data in SQL tables using the INSERT INTO and SELECT commands. It provides syntax and real-life examples for inserting records into an 'employees' table and retrieving all or specific columns of data. Additionally, it demonstrates how to insert multiple rows in a single query.

Uploaded by

Syed Arsalan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

Insert Data in SQL

The document explains how to insert and display data in SQL tables using the INSERT INTO and SELECT commands. It provides syntax and real-life examples for inserting records into an 'employees' table and retrieving all or specific columns of data. Additionally, it demonstrates how to insert multiple rows in a single query.

Uploaded by

Syed Arsalan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

How to Show Table Data in SQL

After creating a table, the next step is:


1. Insert data into the table
2. Display the data

How to Insert Data into a Table


We use:
INSERT INTO
command to add data into a table.

Syntax
INSERT INTO table_name
(column1, column2, column3)
VALUES
(value1, value2, value3);

Real-Life Example
Suppose we have an employees table.
CREATE TABLE employees (
emp_id INT,
emp_name VARCHAR(50),
department VARCHAR(30),
salary DECIMAL(10,2)
);

Insert First Record


INSERT INTO employees
(emp_id, emp_name, department, salary)
VALUES
(101, 'Ahmed', 'HR', 45000);

Insert Second Record


INSERT INTO employees
(emp_id, emp_name, department, salary)
VALUES
(102, 'Sara', 'IT', 65000);

Insert Third Record


INSERT INTO employees
(emp_id, emp_name, department, salary)
VALUES
(103, 'John', 'Sales', 52000);
Table Data After Inserting Records
emp_id emp_name department salary
101 Ahmed HR 45000
102 Sara IT 65000
103 John Sales 52000

How to Show Table Data


We use:
SELECT
command to display data from a table.

Show All Data


Syntax:
SELECT * FROM table_name;
Example
SELECT * FROM employees;
Output
emp_id emp_name department salary
101 Ahmed HR 45000
102 Sara IT 65000
103 John Sales 52000
Explanation
Symbol Meaning
SELECT Retrieve data
* All columns
FROM employees From employees table

Show Specific Columns


Suppose we only want:
• Employee name
• Salary
Query:
SELECT emp_name, salary
FROM employees;
Output
emp_name salary
Ahmed 45000
Sara 65000
John 52000
Insert Multiple Rows Together
We can insert multiple records in one query. Example:
INSERT INTO employees
(emp_id, emp_name, department, salary)
VALUES
(104, 'Ali', 'Finance', 70000),
(105, 'Sara Khan', 'IT', 80000),
(106, 'David', 'Marketing', 60000);

Table After Multiple Inserts


emp_id emp_name department salary
101 Ahmed HR 45000
102 Sara IT 65000
103 John Sales 52000
104 Ali Finance 70000
105 Sara Khan IT 80000
106 David Marketing 60000

You might also like