Lesson 05(Modifying Data)

 

Modifying Data 

(Insert, Update, Delete)


Insert command का प्रयोग table में डाटा भरने के लिए किया जाता है |


Syntax-

insert into table(column1, column2,........) value(value1, value2….)


select * from department;


insert into department values (8, ‘ICE’);

insert into department values (‘temp’, 6); ----error आ जाएगी |

insert into department (dname, deptid) values (‘Temp’, 6) हो जायेगा |



you can insert multiple rows

insert into department values<enter>

→ (7, ‘A’),

→ (8, ‘B’);<enter>


Insert with SELECT statement 

It is used to insert data into table from another table.


insert into table_name

select col1, col2, …. from table_name;



Update Statement

Update statement is used to update existing data in a table .


Syntax-

update table_name

set

col1=exp1

col2=exp2


where condition

We want to change deptname where deptid=7 in dept_temp.

update department_temp

→ set deptname=’Applide Sc.’,

→ where deptid=7;


select * from dept_temp;


update dept_temp

→ set deptname=’test’;


select * from dept_temp;


Update with select statement


Syntax-

update table_name

-->set col1=(nested query)

→ where condition


select * from student;

Sample Query

department_temp में deptid=1 का department वो सेट करना है जिस branch में lalit पढता है |


update dept_temp

→ set department =(select branch from student where  sname = ‘Lalit’)

→ where deptid=1;


Delete Statement

इस command का प्रयोग table में से जानकारी समाप्त करने के लिए किया जाता है |


Syntax -

delete from table_name where condition(Optional)


Delete limit clause  is used to delete specific number of records

delete from dept_temp

→ where deptid=2


select * from dept_temp;


We want to delete first 2 rows.

delete from dept_temp limit 2;


select * from dept_temp;


delete * from dept_temp; 

सारे रिकॉर्ड समाप्त हो जायेंगे |

Comments

Popular posts from this blog

Lesson 07 (Primary Key & Foreign Key)

Lesson 03 (Filter Data)