SlideShare une entreprise Scribd logo
1  sur  6
BASIC DATABASE(MYSQL) QUERIES

1. create database dbname;

  This statement is used to create new database.

2. show databases;
   You can check available databases using show.
3. use dbname;
    When you have multiple databases in your SQL Schema, then before starting your
   operation, you would need to select a database where all the operations would be
   performed. The SQL USE statement is used to select any existing database in SQL
   schema.
4. show tables;
   You can check available tables in specific database using show.
5. create table tname(c1name c1type, c2name c2type, c3name c3type……cnname
   cntype)
   The above statement is used to create new table, it requires to specify the column
   names and type. Type indicates the data to be entered in specific column.
    create table student(sname varchar(25), sroll int, sage int);
6. describe tname
    To view the structure of table, we use describe statement, Suppose if we had
   deleted all the records of the table or the table is empty, and we want to insert new
   record, we must know the structure of the table, ie column name and its datatype.
   The output of describe would look like this.. for ex: describe employee_record

        Field                   Type                  Null
        Ename                   Varchar               yes
        Salary                  Int                   Yes


7. INSERT

   Insert query is use to fill the table or add content to the specific table. It can be used
   in following ways:

         insert into tname values(c1value,c2 value, c3value……cnvalue);

      To insert data in table

         insert into tname (c1name, c3name, c7name,..cnname)values(c1value,
             c7value,..cnvalue);
       To insert data in specific columns only not in all the columns, we need to
      specify the column names.
         insert into t1name( c1name,c2name..cnname)
         select c1name,c2name..cnname from t2name;
      This syntax is used to populate table with data in other existing table.
In the above snapshot we are inserting data into parent table using the data in
child table.


     8. DELETE(Delete query doesnot use *)

     Delete query is used to remove record or delete some record from specific table. If
     delete query is used without Where clause, it will delete all the data in the table.

           Delete from tname where some condition.
           Delete from student where roll_no =4;
           Delete from tname;
           Empty the table
           Delete from tname where age =(select max(age) from tname);
           Delete the record of student whose age is maximum.
In the above snapshop we have deleted all the records where eid and
      eno are same or equal…. In the same way we can apply any condition.

9. SELECT

Select query is used to view the contents of specific table, it can be used as:

      Select * from tname;
      To view all the contents of table. Here * stands for all.
      Select c1name,c2name…cnname from tname;
      To view records of specific columns/fields. For ex select sname from student.
Select * from tname where some condition.
      To view all the contents of table that satisfies the given condition. For ex: select
      * from employee where salary > 10000;

      Select distinct(c1name) from tname;
      To view unique values or unrepeated values of the table’s particular column. For
      ex: select distinct(sname) from student.
      Select count(cname) from tname.
      Counts the no. of records in specific column. for ex: select count(sname) from
      student.
      Select count(distinct(cname)) from tname.
      Counts the distinct no. of records in specific field. For ex: select
      count(distinct(sname)) from student.



10. DROP

Drop query is used to remove table from selected database or to remove whole
database.

      Drop database dbname
      Drop table tname.



11. ALTER (alter query needs the word table explicitly)

Alter query is generally used to change the structure of the table, either by
adding new column or deleting existing column.

      Alter table tname ADD newcname newctype;
      Above statement can be used to add new column to the existing table. Say alter
      table student add parent_name varchar(45);
      Alter table tname DROP cname.
      Above statement can be used to delete existing column from an existing table.
      Say alter table student drop parent_name;
      Alter table tname rename to new_tname;
Above statement can be used to change the name of existing table. For ex: alter
   table student rename to student_record;


12. UPDATE

Update query is used to change the data resinding in the table. Or to change the
content of table, if update query is used without where clause, it will change all the
records of specific column.

Update tname set cname= whatever where some condition.

Update the record of table which satisfies the given condition.

Update student SET age=20 where roll_no =1;

Above statement will change the age to 20 of the student whose rollno is1.Here
student is the table name, age is the columnname and roll_no is another column
name.

                   OR

Update student set sname=’arti sharma’ where roll_no=2.

Above statement will change the name to arti sharma of the student whose rollno
is2.Here student is the table name, sname is the columnname and roll_no is another
column name.

                   OR

Update student set age=20;

 Above statement will change the age of all the students because we have not
specified any condition using where clause.

Contenu connexe

Tendances (17)

Lecture 3 sql {basics ddl commands}
Lecture 3 sql {basics  ddl commands}Lecture 3 sql {basics  ddl commands}
Lecture 3 sql {basics ddl commands}
 
Ddl commands
Ddl commandsDdl commands
Ddl commands
 
Lecture 4 sql {basics keys and constraints}
Lecture 4 sql {basics  keys and constraints}Lecture 4 sql {basics  keys and constraints}
Lecture 4 sql {basics keys and constraints}
 
Data Definition Language (DDL)
Data Definition Language (DDL) Data Definition Language (DDL)
Data Definition Language (DDL)
 
Database Management - Lecture 2 - SQL select, insert, update and delete
Database Management - Lecture 2 - SQL select, insert, update and deleteDatabase Management - Lecture 2 - SQL select, insert, update and delete
Database Management - Lecture 2 - SQL select, insert, update and delete
 
Alter table command
Alter table commandAlter table command
Alter table command
 
Mysql alter-command
Mysql alter-commandMysql alter-command
Mysql alter-command
 
Commands of DML in SQL
Commands of DML in SQLCommands of DML in SQL
Commands of DML in SQL
 
ADBMS Unit-II c
ADBMS Unit-II cADBMS Unit-II c
ADBMS Unit-II c
 
Chapter9 more on database and sql
Chapter9 more on database and sqlChapter9 more on database and sql
Chapter9 more on database and sql
 
SQL(DDL & DML)
SQL(DDL & DML)SQL(DDL & DML)
SQL(DDL & DML)
 
DML Commands
DML CommandsDML Commands
DML Commands
 
Oracle: DDL
Oracle: DDLOracle: DDL
Oracle: DDL
 
Oracle naveen Sql
Oracle naveen   SqlOracle naveen   Sql
Oracle naveen Sql
 
Sql reference from w3 schools
Sql reference from w3 schools Sql reference from w3 schools
Sql reference from w3 schools
 
Sql tables
Sql tablesSql tables
Sql tables
 
SQL
SQLSQL
SQL
 

En vedette

c plus plus programsSlide
c plus plus programsSlidec plus plus programsSlide
c plus plus programsSlideharman kaur
 
Introduction to digital electornics
Introduction to digital electornicsIntroduction to digital electornics
Introduction to digital electornicsharman kaur
 
Sales. Doing it Sillicon Valley style.
Sales. Doing it Sillicon Valley style.Sales. Doing it Sillicon Valley style.
Sales. Doing it Sillicon Valley style.Artem Berman
 
An overview of Ukrainian it market.
An overview of Ukrainian it market.An overview of Ukrainian it market.
An overview of Ukrainian it market.Artem Berman
 
Content Marketing at Kelloggs - BI MN
Content Marketing at Kelloggs - BI MNContent Marketing at Kelloggs - BI MN
Content Marketing at Kelloggs - BI MNKarl Miller
 
Quiz on Logic Gate
Quiz on Logic GateQuiz on Logic Gate
Quiz on Logic Gateharman kaur
 
ਜਪੁ ਜੀ ਸਾਹਿਬ (JAPJI SAHIB)
ਜਪੁ ਜੀ ਸਾਹਿਬ (JAPJI SAHIB)ਜਪੁ ਜੀ ਸਾਹਿਬ (JAPJI SAHIB)
ਜਪੁ ਜੀ ਸਾਹਿਬ (JAPJI SAHIB)harman kaur
 
Virtual function
Virtual functionVirtual function
Virtual functionharman kaur
 
Creating red black tree
Creating red black treeCreating red black tree
Creating red black treeharman kaur
 
Functions oracle (pl/sql)
Functions oracle (pl/sql)Functions oracle (pl/sql)
Functions oracle (pl/sql)harman kaur
 
operator overloading in c++
operator overloading in c++operator overloading in c++
operator overloading in c++harman kaur
 
Rules of inference
Rules of inferenceRules of inference
Rules of inferenceharman kaur
 
Basic c++ programs
Basic c++ programsBasic c++ programs
Basic c++ programsharman kaur
 

En vedette (19)

Diploma3
Diploma3Diploma3
Diploma3
 
c plus plus programsSlide
c plus plus programsSlidec plus plus programsSlide
c plus plus programsSlide
 
Presentation job fair
Presentation   job fairPresentation   job fair
Presentation job fair
 
Digital u1
Digital u1Digital u1
Digital u1
 
Introduction to digital electornics
Introduction to digital electornicsIntroduction to digital electornics
Introduction to digital electornics
 
Sales. Doing it Sillicon Valley style.
Sales. Doing it Sillicon Valley style.Sales. Doing it Sillicon Valley style.
Sales. Doing it Sillicon Valley style.
 
Cpp programs
Cpp programsCpp programs
Cpp programs
 
Najed
NajedNajed
Najed
 
An overview of Ukrainian it market.
An overview of Ukrainian it market.An overview of Ukrainian it market.
An overview of Ukrainian it market.
 
Content Marketing at Kelloggs - BI MN
Content Marketing at Kelloggs - BI MNContent Marketing at Kelloggs - BI MN
Content Marketing at Kelloggs - BI MN
 
Diploma5
Diploma5Diploma5
Diploma5
 
Quiz on Logic Gate
Quiz on Logic GateQuiz on Logic Gate
Quiz on Logic Gate
 
ਜਪੁ ਜੀ ਸਾਹਿਬ (JAPJI SAHIB)
ਜਪੁ ਜੀ ਸਾਹਿਬ (JAPJI SAHIB)ਜਪੁ ਜੀ ਸਾਹਿਬ (JAPJI SAHIB)
ਜਪੁ ਜੀ ਸਾਹਿਬ (JAPJI SAHIB)
 
Virtual function
Virtual functionVirtual function
Virtual function
 
Creating red black tree
Creating red black treeCreating red black tree
Creating red black tree
 
Functions oracle (pl/sql)
Functions oracle (pl/sql)Functions oracle (pl/sql)
Functions oracle (pl/sql)
 
operator overloading in c++
operator overloading in c++operator overloading in c++
operator overloading in c++
 
Rules of inference
Rules of inferenceRules of inference
Rules of inference
 
Basic c++ programs
Basic c++ programsBasic c++ programs
Basic c++ programs
 

Similaire à Msql query

Similaire à Msql query (20)

unit-5 sql notes.docx
unit-5 sql notes.docxunit-5 sql notes.docx
unit-5 sql notes.docx
 
Oracle : DML
Oracle : DMLOracle : DML
Oracle : DML
 
Oraclesql
OraclesqlOraclesql
Oraclesql
 
introdution to SQL and SQL functions
introdution to SQL and SQL functionsintrodution to SQL and SQL functions
introdution to SQL and SQL functions
 
Intro to tsql unit 9
Intro to tsql   unit 9Intro to tsql   unit 9
Intro to tsql unit 9
 
Sql basics v2
Sql basics v2Sql basics v2
Sql basics v2
 
DBMS.pdf
DBMS.pdfDBMS.pdf
DBMS.pdf
 
ADV PPT 2 LAB.pptx
ADV PPT 2 LAB.pptxADV PPT 2 LAB.pptx
ADV PPT 2 LAB.pptx
 
SQL : Structured Query Language
SQL : Structured Query LanguageSQL : Structured Query Language
SQL : Structured Query Language
 
Its about a sql topic for basic structured query language
Its about a sql topic for basic structured query languageIts about a sql topic for basic structured query language
Its about a sql topic for basic structured query language
 
dbms lab manual
dbms lab manualdbms lab manual
dbms lab manual
 
Oracle naveen Sql
Oracle naveen   SqlOracle naveen   Sql
Oracle naveen Sql
 
Sql dml & tcl 2
Sql   dml & tcl 2Sql   dml & tcl 2
Sql dml & tcl 2
 
Mysql Statments
Mysql StatmentsMysql Statments
Mysql Statments
 
Creating database using sql commands
Creating database using sql commandsCreating database using sql commands
Creating database using sql commands
 
ADBMS unit 1.pdfsdgdsgdsgdsgdsgdsgdsgdsg
ADBMS unit 1.pdfsdgdsgdsgdsgdsgdsgdsgdsgADBMS unit 1.pdfsdgdsgdsgdsgdsgdsgdsgdsg
ADBMS unit 1.pdfsdgdsgdsgdsgdsgdsgdsgdsg
 
Les10 Creating And Managing Tables
Les10 Creating And Managing TablesLes10 Creating And Managing Tables
Les10 Creating And Managing Tables
 
SQL report
SQL reportSQL report
SQL report
 
SQL
SQLSQL
SQL
 
My SQL.pptx
My SQL.pptxMy SQL.pptx
My SQL.pptx
 

Dernier

Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 
Indexing Structures in Database Management system.pdf
Indexing Structures in Database Management system.pdfIndexing Structures in Database Management system.pdf
Indexing Structures in Database Management system.pdfChristalin Nelson
 
Mythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWMythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWQuiz Club NITW
 
ICS 2208 Lecture Slide Notes for Topic 6
ICS 2208 Lecture Slide Notes for Topic 6ICS 2208 Lecture Slide Notes for Topic 6
ICS 2208 Lecture Slide Notes for Topic 6Vanessa Camilleri
 
Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1GloryAnnCastre1
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4JOYLYNSAMANIEGO
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxlancelewisportillo
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfVanessa Camilleri
 
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvRicaMaeCastro1
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptxmary850239
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...DhatriParmar
 
Sulphonamides, mechanisms and their uses
Sulphonamides, mechanisms and their usesSulphonamides, mechanisms and their uses
Sulphonamides, mechanisms and their usesVijayaLaxmi84
 
4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptx4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptxmary850239
 
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQ-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQuiz Club NITW
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Projectjordimapav
 
How to Manage Buy 3 Get 1 Free in Odoo 17
How to Manage Buy 3 Get 1 Free in Odoo 17How to Manage Buy 3 Get 1 Free in Odoo 17
How to Manage Buy 3 Get 1 Free in Odoo 17Celine George
 
Using Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea DevelopmentUsing Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea Developmentchesterberbo7
 

Dernier (20)

Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 
Indexing Structures in Database Management system.pdf
Indexing Structures in Database Management system.pdfIndexing Structures in Database Management system.pdf
Indexing Structures in Database Management system.pdf
 
Mythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWMythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITW
 
ICS 2208 Lecture Slide Notes for Topic 6
ICS 2208 Lecture Slide Notes for Topic 6ICS 2208 Lecture Slide Notes for Topic 6
ICS 2208 Lecture Slide Notes for Topic 6
 
Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4
 
Paradigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTAParadigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTA
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdf
 
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
 
prashanth updated resume 2024 for Teaching Profession
prashanth updated resume 2024 for Teaching Professionprashanth updated resume 2024 for Teaching Profession
prashanth updated resume 2024 for Teaching Profession
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
 
Sulphonamides, mechanisms and their uses
Sulphonamides, mechanisms and their usesSulphonamides, mechanisms and their uses
Sulphonamides, mechanisms and their uses
 
4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptx4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptx
 
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQ-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Project
 
How to Manage Buy 3 Get 1 Free in Odoo 17
How to Manage Buy 3 Get 1 Free in Odoo 17How to Manage Buy 3 Get 1 Free in Odoo 17
How to Manage Buy 3 Get 1 Free in Odoo 17
 
Using Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea DevelopmentUsing Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea Development
 

Msql query

  • 1. BASIC DATABASE(MYSQL) QUERIES 1. create database dbname; This statement is used to create new database. 2. show databases; You can check available databases using show. 3. use dbname; When you have multiple databases in your SQL Schema, then before starting your operation, you would need to select a database where all the operations would be performed. The SQL USE statement is used to select any existing database in SQL schema. 4. show tables; You can check available tables in specific database using show.
  • 2. 5. create table tname(c1name c1type, c2name c2type, c3name c3type……cnname cntype) The above statement is used to create new table, it requires to specify the column names and type. Type indicates the data to be entered in specific column. create table student(sname varchar(25), sroll int, sage int); 6. describe tname To view the structure of table, we use describe statement, Suppose if we had deleted all the records of the table or the table is empty, and we want to insert new record, we must know the structure of the table, ie column name and its datatype. The output of describe would look like this.. for ex: describe employee_record Field Type Null Ename Varchar yes Salary Int Yes 7. INSERT Insert query is use to fill the table or add content to the specific table. It can be used in following ways: insert into tname values(c1value,c2 value, c3value……cnvalue); To insert data in table insert into tname (c1name, c3name, c7name,..cnname)values(c1value, c7value,..cnvalue); To insert data in specific columns only not in all the columns, we need to specify the column names. insert into t1name( c1name,c2name..cnname) select c1name,c2name..cnname from t2name; This syntax is used to populate table with data in other existing table.
  • 3. In the above snapshot we are inserting data into parent table using the data in child table. 8. DELETE(Delete query doesnot use *) Delete query is used to remove record or delete some record from specific table. If delete query is used without Where clause, it will delete all the data in the table. Delete from tname where some condition. Delete from student where roll_no =4; Delete from tname; Empty the table Delete from tname where age =(select max(age) from tname); Delete the record of student whose age is maximum.
  • 4. In the above snapshop we have deleted all the records where eid and eno are same or equal…. In the same way we can apply any condition. 9. SELECT Select query is used to view the contents of specific table, it can be used as: Select * from tname; To view all the contents of table. Here * stands for all. Select c1name,c2name…cnname from tname; To view records of specific columns/fields. For ex select sname from student.
  • 5. Select * from tname where some condition. To view all the contents of table that satisfies the given condition. For ex: select * from employee where salary > 10000; Select distinct(c1name) from tname; To view unique values or unrepeated values of the table’s particular column. For ex: select distinct(sname) from student. Select count(cname) from tname. Counts the no. of records in specific column. for ex: select count(sname) from student. Select count(distinct(cname)) from tname. Counts the distinct no. of records in specific field. For ex: select count(distinct(sname)) from student. 10. DROP Drop query is used to remove table from selected database or to remove whole database. Drop database dbname Drop table tname. 11. ALTER (alter query needs the word table explicitly) Alter query is generally used to change the structure of the table, either by adding new column or deleting existing column. Alter table tname ADD newcname newctype; Above statement can be used to add new column to the existing table. Say alter table student add parent_name varchar(45); Alter table tname DROP cname. Above statement can be used to delete existing column from an existing table. Say alter table student drop parent_name; Alter table tname rename to new_tname;
  • 6. Above statement can be used to change the name of existing table. For ex: alter table student rename to student_record; 12. UPDATE Update query is used to change the data resinding in the table. Or to change the content of table, if update query is used without where clause, it will change all the records of specific column. Update tname set cname= whatever where some condition. Update the record of table which satisfies the given condition. Update student SET age=20 where roll_no =1; Above statement will change the age to 20 of the student whose rollno is1.Here student is the table name, age is the columnname and roll_no is another column name. OR Update student set sname=’arti sharma’ where roll_no=2. Above statement will change the name to arti sharma of the student whose rollno is2.Here student is the table name, sname is the columnname and roll_no is another column name. OR Update student set age=20; Above statement will change the age of all the students because we have not specified any condition using where clause.