Zadatak 2. a) Kreirajmo tabelu TRANSAKCIJE koja će pamtiti sve transakcije obavljene na računima korisnika CREATE TABLE `test`.`transakcije` ( `id` INTEGER.

Slides:



Advertisements
Similar presentations
Batches, Scripts, Transactions-SQL Server 7. A batch is a set of Transact-SQL statements that are interpreted together by SQL Server. They are submitted.
Advertisements

MySQL. To start go to Login details: login: labuser password:macimd15 – There.
PL/SQL. Introduction to PL/SQL PL/SQL is the procedure extension to Oracle SQL. It is used to access an Oracle database from various environments (e.g.
MySQL-Database Teppo Räisänen Oulu University of Applied Sciences School of Business and Information Management.
SQL components In Oracle. SQL in Oracle SQL is made up of 4 components: –DDL Data Definition Language CREATE, ALTER, DROP, TRUNCATE. Creates / Alters.
Using Relational Databases and SQL Steven Emory Department of Computer Science California State University, Los Angeles Lecture 9: Data Definition Language.
Murali Mani SQL DDL and Oracle utilities. Murali Mani Datatypes in SQL INT (or) INTEGER FLOAT (or) REAL DECIMAL (n, m) CHAR (n) VARCHAR (n) DATE, TIME.
SQL Keys and Constraints Justin Maksim. Key Declaration Key constraint defined within the CREATE TABLE command Key can be declared using either the PRIMARY.
SQL DDL constraints Restrictions on the columns and tables 1SQL DDL Constraints.
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, Copyright © 2010 All Rights Reserved. 1.
Phonegap Bridge – File System CIS 136 Building Mobile Apps 1.
DBMS 3. course. Reminder Data independence: logical and physical Concurrent processing – Transaction – Deadlock – Rollback – Logging ER Diagrams.
MySql In Action Step by step method to create your own database.
ORACLE SQL. Overview Personal DBMS Vs Client/Server DBMS Oracle 8 Environment SQL – syntax and examples PL/SQL-introduction.
Triggers Event handlers in the DBMS. Triggers are event handlers Triggers a executed when an event happens in the DBMS Example events – INSERT, UPDATE.
Constraints  Constraints are used to enforce rules at table level.  Constraints prevent the deletion of a table if there is dependencies.  The following.
CSC 2720 Building Web Applications Database and SQL.
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, Copyright © 2015, Fred McClurg, All Rights.
Procedure Function Trigger. create table employee ( id number, name varchar2(100), deptno number, salary float, primary key(id) ) create table deptincrease.
Advanced Database Management System
SQL Basics. 5/27/2016Chapter 32 of 19 Naming SQL commands are NOT case sensitive SQL commands are NOT case sensitive But user identifier names ARE case.
Stored Procedures Week 9. Test Details Stored Procedures SQL can call code written in iSeries High Level Languages –Called stored procedures SQL has.
SQL Basics. What is SQL? SQL stands for Structured Query Language. SQL lets you access and manipulate databases.
Dec 8, 2003Murali Mani Constraints B term 2004: lecture 15.
CREATE TABLE CREATE TABLE statement is used for creating relations Each column is described with three parts: column name, data type, and optional constraints.
Advance Database S Week-5 Dr.Kwanchai Eurviriyanukul
DBMS 3. course. Reminder Data independence: logical and physical Concurrent processing – Transaction – Deadlock – Rollback – Logging ER Diagrams.
At the end of this lesson, you will be able to: Describe constraints Create and maintain constraints.
CREATE TABLE ARTIST ( ArtistID int NOT NULL IDENTITY (1,1), Namechar(25) NOT NULL, TEXT ERROR Nationality char (30) NULL, Birthdate numeric (4,0) NULL,
1 Stored Procedures in MySQL Part I. 2 Objectives SQL Vs. MySQL SP MySQL SP Parameters MySQL SP Control Structures.
Working with MySQL A290/A590, Fall /07/2014.
LECTURE FOUR Introduction to SQL DDL with tables DML with tables.
Introduction to MySQL  Working with MySQL and MySQL Workbench.
Introduction to Databases & SQL Ahmet Sacan. What you’ll need Firefox, SQLite plugin Mirdb and Targetscan databases.
Latihan Lock.
MySQL-Database Jouni Juntunen Oulu University of Applied Sciences
Insert, Update and the rest…
CS 3630 Database Design and Implementation
Instructor: Jason Carter
Referential Integrity MySQL
CS311 Database Management system
Isti upit iskazan na različite načine
MySQL Explain examples
Rules in active databases and integrity constraints
ETL Processing Mechanics of ETL.
لغة قواعد البيانات STRUCTURED QUERY LANGUAGE SQL))
The Basics of Data Manipulation
For student, require values for name and address.
InputBox i naredba IF.
DATABASE SQL= Structure Query Language مبادئ قواعد بيانات
Do While ... Loop struktura
SQL Code for Byrnetube video
مقدمة في قواعد البيانات
Temporary versus Permanent Changes to Data
Rob Gleasure robgleasure.com
CS122B: Projects in Databases and Web Applications Winter 2018
CS3220 Web and Internet Programming SQL and MySQL
CS122B: Projects in Databases and Web Applications Spring 2018
Data Definition Language
Chapter # 7 Introduction to Structured Query Language (SQL) Part I.
Chapter 4 Introduction to MySQL.
CS3220 Web and Internet Programming SQL and MySQL
Instructor: Samia arshad
Triggers 7/11/2019 See scm-intranet.
ETL Processing Mechanics of ETL.
កម្មវិធីបង្រៀន SQL Programming ជាភាសាខ្មែរ Online SQL Training Course
CS122B: Projects in Databases and Web Applications Winter 2019
SQL NOT NULL Constraint
SQL (Structured Query Language)
SQL AUTO INCREMENT Field
Presentation transcript:

Zadatak 2. a) Kreirajmo tabelu TRANSAKCIJE koja će pamtiti sve transakcije obavljene na računima korisnika CREATE TABLE `test`.`transakcije` ( `id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, `ovome_oduzmi` INTEGER UNSIGNED, `ovome_dodaj` INTEGER UNSIGNED, `iznos` DOUBLE(10,2), `opis_transakcije` VARCHAR(255), PRIMARY KEY(`id`), CONSTRAINT `FK_transakcije_oduzmi` FOREIGN KEY `FK_transakcije_oduzmi` (`ovome_oduzmi`) REFERENCES `korisnici` (`id`) ON DELETE SET NULL, CONSTRAINT `FK_transakcije_dodaj` FOREIGN KEY `FK_transakcije_dodaj` (`ovome_dodaj`) ON DELETE SET NULL ) ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci COMMENT = 'Lookup tabela sa transakcijama'; b) Kreirati proceduru kojom se vrši prebacivanje novca sa računa jednog korisnika na račun drugog korisnika.

END $$ DELIMITER ; DELIMITER $$ DROP PROCEDURE IF EXISTS `test`.`obavi_transakciju` $$ -- ako ima, onda obavi transakciju: IF v_trenutno_stanje > p_iznos THEN UPDATE korisnici CREATE PROCEDURE `test`.`obavi_transakciju`( SET iznos = iznos - p_iznos IN p_oduzmi_id INT, IN p_dodaj_id INT, IN p_iznos DOUBLE, IN p_opis VARCHAR(255), SET iznos = iznos + p_iznos OUT p_poruka VARCHAR(255)) WHERE id = p_dodaj_id; BEGIN -- sacuvaj informacije o obavljenoj transakciji: DECLARE v_trenutno_stanje DOUBLE(10, 2) DEFAULT 0; INSERT INTO transakcije (id, ovome_oduzmi, ovome_dodaj, iznos, opis_transakcije) VALUES (NULL, p_oduzmi_id, p_dodaj_id, p_iznos, p_opis); DECLARE exit HANDLER FOR NOT FOUND ELSE SET p_poruka = 'Korisnik nema dovoljno novca'; SET p_poruka = 'Korisnik nije pronadjen!'; END IF; DECLARE exit HANDLER FOR SQLEXCEPTION -- potvrdi unos i oznaci kraj transakcije ROLLBACK; -- ili ponisti unos SET p_poruka = 'Greska'; IF p_poruka != '' THEN END; -- oznaci pocetak transakcije COMMIT; START TRANSACTION; SET p_poruka = 'SUCCESS! Transakcija je uspesno obavljena'; -- proveri da li korisnik, kom se skida sa racuna, postoji i da li -- ima dovoljno novca da mu se zadani iznos moze skinuti: SELECT p_poruka; SELECT iznos END $$ INTO v_trenutno_stanje DELIMITER ; FROM korisnici WHERE id = p_oduzmi_id;