Explain about Create, Insert, Select command in structure query language (DBMS)?

DBMSDatabaseBig Data Analytics

Query is a question or requesting information. Query language is a language which is used to retrieve information from a database.

Let’s see some of the structure query language (sql) commands used to perform operations on databases.

Create Command

The create command is used to create table, view, index.

The syntax for the create command is as follows −

Create table tablename(col1 datatype(size), col2 datatype(size),……….colN datatype(size));

For Example,

create table student(name char(30), regno number(10), branch char(20));

Output

The output is the table created below −

NameRegnoBranch

Example

Use the command given below −

create table employee(ename char(30), department varchar(20), age number(10), address varchar(20), Phone number(10));

Output

The output is as follows −

EnameDepartmentAgeAddressPhone

Describe Command

The command used to describe the table is desc.

Syntax

The syntax for the describe command is as follows −

desc tablename

Example 1

Use the command given below −

desc student

Description − It describes the structure / schema of a table.

The output is as follows −

NameNULLType
Name
Char(30)
Regno
Number(10)
Branch
Char(20)

Example 2

Use the command mentioned below −

desc employee

Description − It describes the structure/ schema of a table.

The output is as follows −

NameNULLType
Ename
Char(30)
Department
Varchar(20)
Age
Number(10)
Address
Varchar(30)
Phone
Number(10)

Insert Command

The command used to insert data into the table/view/index in the database using ‘insert’.

Syntax

The syntax for the insert command is as follows −

insert into tablename values(valu1,value2,value3,……valueN);

Example

  • Insert into student values (‘hari’, 100,’CSE’); Output − 1 row created

  • Insert into student values (‘pinky’, 101,’CSE’); Output − 1 row created

  • Insert into student values (‘bob’, 102,’CSE’); Output − 1 row created

  • Insert into student values (‘bhanu’, 103,’CSE’); Output − 1 row created

  • Insert into student values (‘bhanu’, 103,’CSE’); Output − 1 row created

  • Insert into student values (‘pinky’, 101,’CSE’); Output − 1 row created

Select Command

The command used to select columns is select.

Syntax

The syntax for the select command is as follows −

select column1, column2,…….coulmnN from tablename

Example 1

select name,regno,branch from student

Or

select * from student;

Output

NameRegnoBranch
Hari100CSE
Pinky101CSE
Bob102CSE
Bhanu103CSE
Bhanu103CSE
Pinky101CSE

Example 2

Use the command given below −

select distinct name from student;

Description − It displays distinct names in sorted order.

Output

NameRegnoBranch
Bhanu103CSE
Bob102CSE
Hari100CSE
Pinky101CSE
raja
Published on 06-Jul-2021 15:23:22
Advertisements