SQL QUERY……..
SQL is a standard database language
>>>What is SQL?
used to access and manipulate data in databases. SQL
stands for Structured Query Language. It was
developed by IBM Computer Scientists in the 1970s.
By executing queries SQL can create, update, delete,
and retrieve data in databases like MySQL, Oracle,
PostgreSQL, etc. Overall, SQL is a query language that
communicates with databases.
>>>What is Database?
A database is a collection of data that is
organized, which is also called structured data.
>>>SQL Queries:
1. CREATE DATABASE query in SQL is used to
create a new database in the database
management system.
Syntax: create database (Name of the database);
Example: create database mysql;
2. We use the SHOW DATABASES command and it
will return a list of all the databases that exist in
our system.
Syntax: show databases;
3. USE Statement is use to a specific database in
SQL,
Syntax: use (Name of the database);
Example: use mysql;
A CREATE DATABASE statement is used to create
a database.
A database consists of tables and inside the tables,
we store the data.
The database name is case-insensitive, so we need
to create a unique database name.
Keep the limit of database names to 128
characters.
>>>Some of The Most Important SQL
Commands
SELECT - extracts data from a database
UPDATE - updates data in a database
DELETE - deletes data from a database
INSERT INTO - inserts new data into a database
CREATE DATABASE - creates a new database
ALTER DATABASE - modifies a database
CREATE TABLE - creates a new table
ALTER TABLE - modifies a table
DROP TABLE - deletes a table
CREATE INDEX - creates an index (search key)
DROP INDEX - deletes an index
1. SQL DROP DATABASE statement is a powerful
command used to permanently delete an existing
database from a database management system.
2. To change the name of a table in SQL, use the
ALTER TABLE current_table_name;
MODIFY [new_table_name];
syntax:
3. The CREATE TABLE command is a crucial tool for
database administration
CREATE table table_name
(
Column1 datatype (size),
column2 datatype (size),
.
.
columnN datatype(size)
);
4. To add data to the table, we use INSERT
INTO command
INSERT INTO table_name (column1, column2, …)
VALUES (value1, value2, …);
5. The SELECT statement in SQL is used to query
and retrieve data from a database.
To see table,we use this select statement with this
syntax;
SELECT * FROM Table_name;
6. SELECT name, age FROM employees;
7. SELECT name, age FROM employees WHERE age
>= 35;
8. SELECT name, age FROM employees ORDER BY
age DESC;
9. We can Create Table From Another Table
CREATE TABLE SubTable AS
SELECT CustomerID, CustomerName
FROM customer;
Note: We can use * instead of column name to copy
whole table to another table.
We can also add constraint to table like NOT
NULL, UNIQUE, CHECK, and DEFAULT.
10. The DESC table_name; command can be used
to display the structure of the created table
10.The DROP TABLE statement in SQL is used to
delete a table and all of its data from the database
permanently.
Drop table table name;
11.SQL DELETE is a basic SQL operation used to
delete data in a database.
DELETE FROM table_name
WHERE some_condition;
SQL ALTER TABLE command. If you need to rename a
table, add a new column, or change the name of an
existing column in SQL, the ALTER command is crucial
for making schema changes without affecting the data
that is already there.
12.Lets Add a new column in Existing Table so
ALTER TABLE table_name ADD
new_column_name(datatype);
We can update this too just like this
update hood set Area ='Delhi' where age>15;
13. Change the name of existing Column,
ALTER TABLE table_name Rename old_column_name
to new_name;