InterviewSolution
| 1. |
Crud Operations in SQL |
|
Answer» CRUD is an abbreviation for Create, Read, Update and Delete. These 4 operations comprise the most basic database operations. The relevant commands for these 4 operations in SQL are:
The above image shows the pillars of SQL CRUD operations.
SQL Syntax: INSERT INTO name_of_table(column1, column2, ....)VALUES(value1, value2, ....) Example: INSERT INTO student(ID, name, phone, class)VALUES(1, 'Scaler', '+1234-4527', 12) For multiple rows, SQL Syntax: INSERT INTO name_of_table(column1, column2, ....)VALUES(value1, value2, ....), (new_value1, new_value2, ...), (....), ... ; Example: INSERT INTO student(ID, name, phone, class)VALUES(1, 'Scaler', '+1234-4527', 12), (2, 'Interviewbit', '+4321-7654', 11); The above example will insert into the student table having the values 1, Scaler, +1234-5678 and 12 to the columns ID, name, phone and class columns.
SQL Syntax: SELECT column1,column2,.. FROM name_of_table;Example: SELECT name,class FROM student;The above example allows the user to read the data in the name and class columns from the student table.
SQL Syntax: UPDATE name_of_tableSET column1=value1,column2=value2,... WHERE conditions...; Example: UPDATE customersSET phone = '+1234-9876' WHEREID = 2; The above SQL example code will update the table ‘customers’ whose ID is 2 with the new given phone number.
The Delete command is used to delete or remove some rows from a table. It is the ‘D’ component of CRUD. SQL Syntax: DELETE FROM name_of_tableWHERE condition1, condition2, ...; Example: DELETE FROM studentWHERE class = 11; The above SQL example code will delete the row from table student, where the class = 11 conditions becomes true. |
|