Sql mutations

From wikinotes
Revision as of 16:38, 6 March 2021 by Will (talk | contribs) (Created page with "= Insertion = <blockquote> You create new rows using the <code>INSERT</code> statement. <syntaxhighlight lang="MySQL"> #### Basic Insert ## table ( columns...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Insertion

You create new rows using the INSERT statement.

#### Basic Insert
##          table (          columns                     )
##            |                 |
INSERT INTO tasks(subject,start_date,end_date,description)
VALUES ('Task 1','2010-01-01','2010-01-02','Description 1'),
       ('Task 2','2010-01-01','2010-01-02','Description 2'),
       ('Task 3','2010-01-01','2010-01-02','Description 3');


#### Insert Where Not Exist
INSERT INTO table_listnames (name, address, tele)
SELECT * FROM (SELECT 'Rupert', 'Somewhere', '022') AS tmp
WHERE NOT EXISTS (
    SELECT name FROM table_listnames WHERE name = 'Rupert'
) LIMIT 1;


#### Update where column already exists
UPDATE userTable
set    email = 'will@mfw'
WHERE  user_Id = 190;

Deletion

DELETE FROM userDepartmentTable          ##Deleting Rows works just like adding them
WHERE project_Id = 43 
AND   user_Id    = 190;