-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathscripts sql.txt
115 lines (86 loc) · 2.91 KB
/
scripts sql.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
CREATE TABLE categoria(
idC int NOT NULL AUTO_INCREMENT,
nombre varchar(60) NOT NULL,
PRIMARY KEY(idC)
);
INSERT INTO categoria(nombre)
VALUES ('Flash'),('Camara'),('Memoria'),('Tripode'),('Filtro');
# HeidiSQL Dump
#
# --------------------------------------------------------
# Host: 127.0.0.1
# Database: webmarket
# Server version: 10.1.19-MariaDB
# Server OS: Win32
# Target compatibility: ANSI SQL
# HeidiSQL version: 4.0
# Date/time: 2017-09-26 17:31:14
# --------------------------------------------------------
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='ANSI,NO_BACKSLASH_ESCAPES';*/
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;*/
#
# Database structure for database 'webmarket'
#
CREATE DATABASE /*!32312 IF NOT EXISTS*/ "webmarket" /*!40100 DEFAULT CHARACTER SET latin1 */;
USE "webmarket";
#
# Table structure for table 'categoria'
#
CREATE TABLE /*!32312 IF NOT EXISTS*/ "categoria" (
"idC" int(11) NOT NULL AUTO_INCREMENT,
"nombre" varchar(60) NOT NULL,
PRIMARY KEY ("idC")
) AUTO_INCREMENT=6;
#
# Dumping data for table 'categoria'
#
LOCK TABLES "categoria" WRITE;
/*!40000 ALTER TABLE "categoria" DISABLE KEYS;*/
REPLACE INTO "categoria" ("idC", "nombre") VALUES
(1,'Flash');
REPLACE INTO "categoria" ("idC", "nombre") VALUES
(2,'Camara');
REPLACE INTO "categoria" ("idC", "nombre") VALUES
(3,'Memoria');
REPLACE INTO "categoria" ("idC", "nombre") VALUES
(4,'Tripode');
REPLACE INTO "categoria" ("idC", "nombre") VALUES
(5,'Filtro');
/*!40000 ALTER TABLE "categoria" ENABLE KEYS;*/
UNLOCK TABLES;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE;*/
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;*/
USE webmarket;
CREATE TABLE productos (
idP int NOT NULL AUTO_INCREMENT,
marca varchar(60) NOT NULL,
descripcion varchar(60) NOT NULL,
origen varchar(60) NOT NULL,
precio int NOT NULL,
categoria int NOT NULL,
PRIMARY KEY (idP)
);
ALTER TABLE productos
ADD CONSTRAINT FK_categoria FOREIGN KEY(categoria) REFERENCES categoria(idC)
INSERT INTO productos(marca,descripcion,origen,precio,categoria)
VALUES('Xanxi','Flash de Camara','china',200,1),
('Wolf','Camara','alemania',500,2),
('Mahjong','Memoria SD','china',20,3),
('GoPro','Tripode para Camara','usa',50,4),
('Parker','Filtro de Camara','usa',50,5);
SELECT productos.idP,productos.marca,productos.descripcion,productos.origen,productos.precio,categoria.nombre
FROM productos
INNER JOIN
categoria
ON
productos.categoria = categoria.idC;
SELECT productos.idP,productos.marca,productos.descripcion,productos.origen,productos.precio,categoria.nombre
FROM productos
INNER JOIN
categoria
ON
productos.categoria = categoria.idC
WHERE productos.idP=4;
SELECT productos.* , categoria.nombre FROM productos
INNER JOIN categoria ON productos.categoria = categoria.idC
ORDER BY productos.idP;