All SQL SYNTAX OF DATABASES
1. HOW TO CREAE DATABASE?
SYNTAX- create database database_name;
Example:
mysql> CREATE DATABASE TOTALSACH;
2. HOW TO SHOW DATABASE LIST?
SYNTAX: show databases;
Example:
mysql> SHOW DATABASES;
3. HOW TO USE DATABASE?
SYNTAX- use database_name;
Example:
mysql> USE TOTALSACH;
4. HOW TO CREAE TABLE IN A DATABASE?
SYNTAX- create table table_name (column1 datatype(), column2 datatype(), colunm3 datatype(), column4 datatype());
Example:
mysql> CREATE TABLE STUDENTS (SRNO INT, NAME VARCHAR(20), CONTACT INT, SALARY VARCHAR(10));
4. HOW TO RENAME TABLE IN A DATABASE?
SYNTAX- alter table old_table_name
rename to new_table_name;
Example:
mysql> alter table studentsss
rename to student;
5. HOW TO INSERT VALUES IN TABLE?
SYNTAX- insert into table_name values(values1, "value2", value3, "value4");
Example:
mysql> INSERT INTO STUDENTS VALUES(1,"MUSKAN", 9876543210, "90000");
6. HOW TO INSERT MULTIPLE DATA IN TABLE?
SYNTAX- insert into table_name values
(values1, "value2", value3, "value4"),
(values1, "value2", value3, "value4"),
(values1, "value2", value3, "value4");
Example:
mysql> INSERT INTO STUDENTS VALUES
(2,"ARTI", 9123456789, 80000),
(3,"MODI", 9223456789, "70000"),
(4,"ARVIND", 9423456789, 80000);
7. HOW TO SHOW TABLE?
SYNTAX- select * from table_name;
Example:
8. HOW TO SHOW DESCRIPTION OF TABLE?
SYNTAX- desc table_name;
Example:
9. HOW TO DELETE DATABASE?
SYNTAX- drop database_name;
Example:
10. HOW TO DELETE TABLE?
SYNTAX- drop table_name;
Example:
11. HOW TO DELETE ROW/TUPLE?
SYNTAX- delete from table_name where fieldname=its value;
Example:
mysql> delete from totalsach where column1=its value;
12. HOW TO DELETE COLUMN?
SYNTAX- alter table table_name
drop column column1;
Example:
mysql> alter table students
drop column "salary";
13. HOW TO MODIFY DATATYPE?
SYNTAX- alter table table_name;
modify field_name datatype;
Example:
mysql> alter table students
modify salary varchar(20);
14. HOW TO UPDATE VALUE IN TABLE?
SYNTAX- update table_name set field_name1="field_value1" where field_name="field_value2";
Example:
mysql> update students set salary="25000" where Name="Raman";
15. HOW TO ADD COLUMN IN TABLE?
SYNTAX- update table_name set field_name1="field_value1" where field_name="field_value2";
Example:
mysql> update students set salary="25000" where Name="Raman";
16. HOW TO ADD ROW/TUPLE IN TABLE?
SYNTAX- insert into table_name values(2, "varun", "sharma", "barabanki", 9876543210, 50000);
Example:
mysql> insert into students values(2, "varun", "sharma", "barabanki", 9876543210, 50000);
16. HOW TO DELETE ROW/TUPLE IN TABLE?
SYNTAX- delete into table_name values(2, "varun", "sharma", "barabanki", 9876543210, 50000);
Example:
mysql> insert into students values(2, "varun", "sharma", "barabanki", 9876543210, 50000);
17. HOW TO RENAME COLUMN NAME?
SYNTAX- alter table table_name
rename column column_old to column_new;
Example:
mysql> alter table table_name
rename column mobile to phone;
18. HOW TO FIND GROUPED DATA IN TABLE?
SYNTAX- select column1 from table_name group by column2;
Example:
mysql> select name from table_name group by address;
19. HOW TO FIND DUPLICATE DATA IN TABLE?
SYNTAX- select * from table_name where cloumn_name="value";
Example:
mysql> select * from students where address="barabanki";
20. HOW TO FILL SAME DATA IN SAME COLUMN?
SYNTAX- update table_name set column_name="value" where column_name2>0;
Example:
mysql> update students set pincode="225001" where srno>0;