You are on page 1of 13

CRUD – Fundamentals of SQL Operation

C CREATE / INSERT

R READ / SELECT

U UPDATE

D DELETE
CREATE
/*Creating Database*/
CREATE DATABASE databasename;

/*Creating Table*/
CREATE TABLE table_name (
    column1 datatype,
    column2 datatype,
    column3 datatype,
   ....
);
CREATE

/*Creating Table* FROM another table/

CREATE TABLE new_table


AS (SELECT * FROM old_table);
INSERT
/*Specifying Columns*/
INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);

/*All Columns*/
INSERT INTO table_name VALUES
(value1, value2, value3, ……);

/*From another table*/


INSERT INTO table_name1
SELECT * FROM table_name2
Consider the following code written
for creating the table:
A. BALANCE must be NOT NULL
CREATE TABLE ACCOUNT B. ACCNO must be NOT NULL
(ACCNO INT , ACCNAME C. Primary key is missing for
VARCHAR(30) NOT NULL,BALANCE ); ACCOUNT
D. BALANCE must have a datatype

The table is NOT getting created,


identify the reason.
READ/SELECT
SELECT column1, column2, ...
FROM table_name;

SELECT * FROM table_name;

SELECT DISTINCT column1, column2, ...
FROM table_name;
Which of the following statement contains an error ?

A. Select * from employee where empid = 10003;


B. Select empid from employee where empid = 10006;
C. Select empid from employee;
D. Select empid where empid = 1009 and last name = ‘Jones';
UPDATE
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;

WHERE clause is very important

Be careful when updating records. If you omit the WHERE clause, ALL
records will be updated!
DELETE
DELETE FROM table_name WHERE condition;
Which of the following SQL
Statement is used to remove rows
from a table.

A. DROP
B. REMOVE ROW
C. DELETE
D. DELETE ROW
Which of the following SQL
Statement is used to remove rows
from a table.

A. DROP
B. REMOVE ROW
C. DELETE
D. DELETE ROW
THANK YOU!

You might also like