Website Development Prices

Search Blog

Tuesday, May 12, 2015

Unosenje podataka u bazu (Inserting data into the database)

Sintaksa za unosenje podataka u bazu

INSERT [INTO] tabela [(kolona1, kolona2, kolona3,...)] VALUES (vrednost1, vrednost2, vrednost3,...);

Primer:

insert into kupci values
(NULL, 'Petar Petrovic', 'Petrova 11', 'Beograd');

Objasnjenje: rec tabela zamenili smo odgovarajucom tabelom kupci, a vrednost1, vrednost2, vrednost3 konkretnim vrednostima. Za brojeve i datume navodnici nisu potrebni. Vrednost NULL smo stavili zato sto smo prilikom definisanja baze podataka volimmotore stavili za kolonu sifrakupca kao AUTO)INCREMENT sto znaci da MySQL , kada tabeli dodate nov red s vrednoscu NULL ili bez vrednosti u tom polju , automatski generisati upisati sledeci redni broj. 


ako zelite da popunite samo neke kolone ili zelite da ih popunite drugacijim redosledom, navedite ih pojedinacno u delu iskaza koji je predvidjen za kolone.

Primer:

insert into kupci (ime, grad) values
('NIkola Nikolic', 'Samobor');

Ovaj oblik iskaza je koristan ako imate podatke samo za deo polja u zapisu ili ako zapisu postoje neobavezna polja.

Isti rezultat mozete postici i ovako

Primer: 

insert into kupci
set name='Stevan Stevanic',
      adresa='Stevanova 33',
      grad='Split';

Sledeci kod sacuvajte kao unosenje-podataka.sql.

/* koristite ovaj samo ako koristite mysql iz komandne linije. U phpmyadminu nije potreban.
Use this only if you use the mysql command line. In the phpMyAdmin is not required.
use motori;
*/

insert into kupci values
  (NULL, "Petar Petrovic", "Petrova 11", "Beograd"),
  (NULL, "Nikola Nikolic", "Nikoliceva 22", "Samobor"),
  (NULL, "Steva Stevanic", "Stevanova 33", "Split");

insert into porudzbine values
  (NULL, 3, 7559.00, "2007-04-02"),
  (NULL, 1, 2278.00, "2012-07-15"),
  (NULL, 2, 3591.00, "2013-08-19"),
  (NULL, 3, 5244.00, "2015-05-01");

insert into motori values
  ("174113002", "KTM", "KTM 125 EXC 2015", 9995.00),
  ("474113002", "Suzuki", "2014 GSX-R1000", 10999.00),
  ("674113002", "Honda", "2014 Honda CB1000R", 11760.00),
  ("774113002", "BMW", " 2015 BMW F800R", 9950.00);

insert into stvari_porudzbina values
  (1, "174113002", 2),
  (2, "474113002", 1),
  (3, "774113002", 2),
  (3, "674113002", 1),
  (4, "474113002-1", 3);

insert into pregled_motora values
  ("474113002", "Ovaj motor je veci deo onoga sto je potrebno da bude brz
                 pratitelj i nudi brzim vozacima cvrstu

                 platformu  za gradjenje svog motora iz snova..");


1. Pokrenite XAMPP. Kliknite na Admin u liniji MySQL-a ili ukucajte u address bar http://localhost/phpmyadmin/

2. Sa leve strane izaberite bazu podataka volimmotore, a sa desne izberite tabelu motori.

3. Kliknite na karticu SQL i obrisite kod ako se pojavio.

4. Ubacite kod iz fajla unosenje-podataka.sql i kliknite dugme "Go"

5. Klik na karticu Browse.
Na engleskom pisemo rezervisane reci velikim slovima da bi se razlikovale od imena tabela, kolona, itd.

In English we write reserved words in capital letters to distinguish them from the names of tables, columns, and so on.

The syntax for inserting data into the database

INSERT [INTO] table [(column1, column2, column3, ...)] VALUES (value1, value2, value3, ...);

Example:

INSERT INTO customers VALUES
(NULL, "Petar Petrovic", "Petrova 11", "Belgrade");

Explanation: the word table we replaced the appropriate table customers, and value1, value2, value3 with concrete values. For numbers and dates double quotes are not required. The value NULL we put because we were when defining the database lovemotobikes for the column customerid put as AUTO_INCREMENT which means that MySQL, when you add a new row to the table with the value NULL or no value in this field, automatically generate thenext following number.

If you want to fill only some columns or you would like to fill in a different order, list them individually in the part of the statement which is intdnded for the column.

Example:

INSERT into customers (name, city) VALUES
('Nikola Nikolic', 'Samobor');

This form of the statement is useful if you have data only for part of the field in the record or if there are in record optinal fields.

The same result can be achieved and thus

Example:

INSERT INTO customers
SET name='Stevan Stevanic',
      address='Stevanova 33',
      city='Split';

Next code save as inserting-data.sql.

/* Use this only if you use the mysql command line. In the phpMyAdmin is not required.

use motobikes;
*/

INSERT INTO customers VALUES
  (NULL, "Petar Petrovic", "Petrova 11", "Beograd"),
  (NULL, "Nikola Nikolic", "Nikoliceva 22", "Samobor"),
  (NULL, "Steva Stevanic", "Stevanova 33", "Split");

INSERT INTO orders VALUES
  (NULL, 3, 7559.00, "2007-04-02"),
  (NULL, 1, 2278.00, "2012-07-15"),
  (NULL, 2, 3591.00, "2013-08-19"),
  (NULL, 3, 5244.00, "2015-05-01");

INSERT INTO motobikes VALUES
  ("174113002", "KTM", "KTM 125 EXC 2015", 9995.00),
  ("474113002", "Suzuki", "2014 GSX-R1000", 10999.00),
  ("674113002", "Honda", "2014 Honda CB1000R", 11760.00),
  ("774113002", "BMW", " 2015 BMW F800R", 9950.00);

INSERT INTO orders_items VALUES
  (1, "174113002", 2),
  (2, "474113002", 1),
  (3, "774113002", 2),
  (3, "674113002", 1),
  (4, "474113002-1", 3);

INSERT INTO motobike_review VALUES
  ("474113002", "This motobike is a major part of what it takes to be fast companion and offers fast drivers firm platform for construction of its dream motobike.");

1. Start XAMPP. Click on the Admin in line MySQL or type in the address bar http://localhost/phpmyadmin/
2. From the left panel select the database lovemotobikes, and on the right, select a table motobikes.
3. Click the tab SQL and delete code if any.
4. Insert the code from the file inserting-data.sql and click button "Go".

5. Click on the Browse tab.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.