Sql commands with example


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

Suggested Posts

Sql merge statement with example
Sql merge statement with example

SQL MERGE statement
In SQL, the MERGE statement is used to combine data from two or more tables into a single table. It allows you to update, insert, or delete data in a target table based on data from a source table.

Read full article
What is Sql | Examples of common SQL queries
What is Sql | Examples of common SQL queries

SQL (Structured Query Language) is a programming language used for managing and accessing data stored in relational databases. It is a standard language for working with relational databases, and it is used by many popular database management systems, such as MySQL, Oracle, and Microsoft SQL Server.

Read full article
Update query in mysql php | Complete explaination of Sql Update query
Update query in mysql php | Complete explaination of Sql Update query

To update data in a MySQL database using PHP, you can use the following steps:
Connect to the MySQL database using the mysqli_connect() function, which takes the database server hostname, username, password, and database name as arguments.

Read full article
MySql – how to connect to database
MySql – how to connect to database

How to connect to database in MySql
To connect to a MySQL database, you need to use a MySQL client. Here is an example of how to connect to a MySQL database using the mysql command-line client:

Read full article