Sql commands with example

by Yogi P - December 8, 2022

SQL (Structured Query Language) is a programming language used for managing and accessing data stored in relational databases. SQL uses a set of commands, known as SQL queries, to interact with the database. These SQL commands and SQL queries allow users to retrieve, insert, update, or delete data from the database.

Some common SQL commands include:

  • SELECT: retrieves data from one or more tables in the database
  • INSERT: adds new records to a table
  • UPDATE: modifies existing records in a table
  • DELETE: removes records from a table
  • CREATE: creates a new database or table
  • ALTER: modifies the structure of an existing database or table
  • DROP: deletes a database or table
  • TRUNCATE: removes all records from a table, but does not delete the table itself
  • INDEX: creates an index on a table, which can be used to speed up data retrieval

These are just a few examples of the many different SQL commands that are available. SQL is a powerful and flexible language, and there are many other commands and features that you can use to manage and query your data.

Here are some examples of common SQL commands:
SELECT:
SELECT * FROM users;

This query retrieves all rows and columns from the users table.

INSERT:
INSERT INTO users (name, email) VALUES ('Yogi Raj', '[email protected]');

This query inserts a new record into the users table, with the specified values for the name and email columns.

UPDATE:
UPDATE users SET name = 'Jane Doe' WHERE id = 1;

This query updates the name column of the record with id 1 in the users table, setting its value to ‘Jane Doe’.

DELETE:
DELETE FROM users WHERE id = 1;

This query deletes the record with id 1 from the users table.

CREATE:
CREATE TABLE users (
id INT PRIMARY KEY AUTO_INCREMENT,
nameVARCHAR(255),
email VARCHAR(255)
);

This query creates a new table called users, with the specified columns and data types.

ALTER:
ALTER TABLE users ADD COLUMN age INT;

This query adds a new column called age to the users table.

DROP:

DROP TABLE users;

This query deletes the users table from the database.
TRUNCATE:
TRUNCATE TABLE users;

This query removes all records from the users table, but does not delete the table itself.

INDEX:
CREATE INDEX email_index ON users (email);

This query creates an index on the email column of the users table, which can be used to speed up data retrieval.

These are just a few examples of common SQL commands. There are many other commands and features available in SQL, and it is worth learning more about the language to fully understand its capabilities.

Share on: Share YogiRaj B.Ed Study Notes on twitter Share YogiRaj B.Ed Study Notes on facebook Share YogiRaj B.Ed Study Notes on WhatsApp
Latest Posts

CDMA Full Form

April 19, 2024

Table of 14

April 11, 2024

Tables 11 to 20

March 11, 2024

Tense Chart

December 22, 2023

Table of 13

December 20, 2023
Search this Blog
Categories