CIM 1101: Module 1

studied byStudied by 0 people
0.0(0)
Get a hint
Hint

SQL Query for creating multiple tables

1 / 9

flashcard set

Earn XP

Description and Tags

Module 1 of CIM 1101 (Information Management)

10 Terms

1

SQL Query for creating multiple tables

create table customer(CID int(3) not null, auto_increment, CName varchar(20), Address varchar(20), primary key(CID));\n \ncreate table orders (OID int not null, CID int references customer(CID), primary key(OID));

New cards
2

SQL Query for Inserting records in both tables

insert into customer values (111, 'Michael', 'Caloocan'), (222, 'Lync','Quezon City'), (333,'Tbag','Manila');\n \ninsert into orders values (400, 567),(700,123),(900,222);

New cards
3

SQL Query for Any or All

select CName from customer where CName <> all (Select CName from customer);\n \nselect CName from customer where CName <> all (Select CName from customer);\n \nselect CName from customer where CName = all(select CName from customer);\n \nselect CName from customer where CName = all(select CName from customer where CName ='Tbag');\n \nselect CName from customer where CName = any(select CName from customer);

New cards
4

SQL Query for Having

select * from customer having Address = 'Caloocan';\n \nselect * from customer having Address in (select Address from customer);\n \nselect * from customer having Address in (select Address from customer where Address = 'Caloocan');

New cards
5

SQL Query for Intersect / IN

select * from customer where customer.CID in (select orders.CID from orders);\n \nselect * from customer where customer.CID >200 and customer.CID in (select orders.CID from orders where orders.OID >300);

New cards
6

This is a database object associated with a table that is automatically activated in when an action such as insert, delete and update occurs in the associated table.

MySQL trigger

New cards
7

Row-level trigger

This is automatically invoked activated for each row that is inserted, updated, or deleted in the associated table.

New cards
8

Statement-level trigger

This is executed once for every transaction in the table no matter how many rows are affected by such action.

New cards
9

SQL Query for trigger

DELIMITER //\nCREATE TRIGGER tr_log_inserts AFTER INSERT ON customer FOR EACH ROW\nBEGIN\nINSERT INTO audit_logs(module, remarks, datetimestamp) values ('Customers',concat('INSERT row for CID ',NEW.CID),now());\nEND//\nDELIMITER ;\n \n \n \n \nDELIMITER //\nCREATE TRIGGER tr_log_updates AFTER UPDATE ON customer FOR EACH ROW\nBEGIN\nINSERT INTO audit_logs(module, remarks, datetimestamp) values ('Customers',concat('UPDATE Name=', OLD.CName, '=>', New.CName,' for CID ',OLD.CID),now());\nEND//\nDELIMITER ;

New cards
10

SQL Query for Stored Procedure

DELIMITER //\nCREATE PROCEDURE sp_InsertCustomer(paramCID INT(2), paramName VARCHAR(20), paramAddress VARCHAR(20))\nBEGIN\nINSERT INTO customer(CID, CName, Address) VALUES(paramCID, paramName, paramAddress);\nEND//\nDELIMITER ;\n \n \n \nDELIMITER //\nCREATE PROCEDURE sp_AllCustomers()\nBEGIN\nselect * from customer;\nEND//\nDELIMITER ;

New cards

Explore top notes

note Note
studied byStudied by 28 people
... ago
5.0(1)
note Note
studied byStudied by 10 people
... ago
5.0(1)
note Note
studied byStudied by 10 people
... ago
5.0(1)
note Note
studied byStudied by 3 people
... ago
5.0(1)
note Note
studied byStudied by 13 people
... ago
5.0(1)
note Note
studied byStudied by 8 people
... ago
5.0(1)
note Note
studied byStudied by 31 people
... ago
5.0(2)

Explore top flashcards

flashcards Flashcard (255)
studied byStudied by 13 people
... ago
5.0(1)
flashcards Flashcard (56)
studied byStudied by 6 people
... ago
5.0(1)
flashcards Flashcard (20)
studied byStudied by 12 people
... ago
5.0(2)
flashcards Flashcard (38)
studied byStudied by 24 people
... ago
5.0(1)
flashcards Flashcard (72)
studied byStudied by 132 people
... ago
5.0(3)
flashcards Flashcard (87)
studied byStudied by 2 people
... ago
5.0(1)
flashcards Flashcard (96)
studied byStudied by 22 people
... ago
5.0(1)
flashcards Flashcard (485)
studied byStudied by 305 people
... ago
5.0(6)
robot