-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBase de datos
80 lines (55 loc) · 1.3 KB
/
Base de datos
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
SQL CHEATSHEET --> https://www.sqltutorial.org/sql-cheat-sheet/
## Crear tablas ##
CREATE TABLE Productos(
ID INT,
DESCRIPCION VARCHAR(50) NOT NULL,
STOCKACTUAL INT,
STOCKMÍNIMO INT,
PVP INT,
PRIMARY KEY(ID)
);
CREATE TABLE VENTAS(
IDVENTA INT,
FECHAVENTA DATE NOT NULL,
IDCLIENTE INT,
IDPRODUCTO INT,
CANTIDAD INT,
PRIMARY KEY(IDVENTA),
FOREIGN KEY(IDCLIENTE) REFERENCES Clientes(ID),
FOREIGN KEY(IDPRODUCTO) REFERENCES Productos(ID)
);
## Iner Join ##
SELECT column_name(s)
FROM table1
INNER JOIN table2
LEFT JOIN (TABLA)
RIGHT JOIN (TABLA)
ON table1.column_name = table2.column_name;
## All/Any ##
select * from profesores
where edad>all/any(select edad from alumnos)
//all necesita que todos sean true
any con que uno sea true te lo devuelve
## Count ##
select count(nombre)
from personas
where nombre like 'p_p_'
select count(distinct (nombre)) //esto solo da los nombres diferentes.
## GroupBy/OrderBy ##
SELECT column_name(s),count(*)
FROM table_name
WHERE condition
GROUP BY column_name(s)
ORDER BY column_name(s);
## Procedure ##
CREATE procedure modificarCliente
AS
print 'hola mundo'
GO
## Like ##
select nombre
from personas
where nombre like '%paco%' aqui te daria todo lo que contenga paco
select nombre
from personas
where nombre like 'p_c_'