Home » Online Computer Education » Learn online DBMS “Insert Command in MySQL” Complete Lesson 11

Learn online DBMS “Insert Command in MySQL” Complete Lesson 11

 

INSERT COMMAND – This command is used to insert a tuple in a relation. We must specify the name of the relation in which tuple is to be inserted and the values. The values must be in the same order as specified during the Create Table command. For example, consider the following table Teacher:

CREATE TABLE Teacher

 (

Teacher_Namevarchar(20) NOT NULL,

Teacher_IDinteger,

Dept_Nointeger DEFAULT 234,

  Subject varchar(20)

);

 

To insert a tuple in the Teacher table INSERT command can be used as shown below:

Insert Into Teacher

Values (“Shanaya”, 345, 5, “Computer Science”);

Note that the values listed above are in the same order of the attributes as specified in the Create Table command.

Another form of INSERT command is used to insert a tuple in which the ordering of values is done by explicitly specifying the attribute names as shown below:

 

Insert Into Teacher (Teacher_ID, Teacher_Name, Subject)

Values (2345, “Alice”, “History”);

Insert1

 

We have used the Select Command to display all the rows of the Teacher Table. This command is explained later in detail.

Note that the values entered are ordered with respect to the attributes mentioned. The attributes that have not been specified are those with NULL allowed or DEFAULT values. Thus in the above example Dept_No is not specified hence it will take its default value i.e 234 as given in the table creation command.

About

The main objective of this website is to provide quality study material to all students (from 1st to 12th class of any board) irrespective of their background as our motto is “Education for Everyone”. It is also a very good platform for teachers who want to share their valuable knowledge.

Leave a Reply

Your email address will not be published.