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 * FROM users;
This query retrieves all rows and columns from the users table.
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 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 FROM users WHERE id = 1;
This query deletes the record with id 1 from the users table.
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 TABLE users ADD COLUMN age INT;
This query adds a new column called age to the users table.
DROP TABLE users;
TRUNCATE TABLE users;
This query removes all records from the users table, but does not delete the table itself.
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.