-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsql\01_create_databases.sql
More file actions
57 lines (52 loc) · 2.07 KB
/
sql\01_create_databases.sql
File metadata and controls
57 lines (52 loc) · 2.07 KB
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
/* =============================================================================
Archivo: 01_create_databases.sql
Propósito: Crear las TRES bases de datos que simulan tres bibliotecas en
ubicaciones físicas distintas.
Autor: Aiko Taniguchi
Uso: Ejecutar UNA sola vez al principio, desde SSMS conectado a
.\SQLEXPRESS con autenticación de Windows.
Notas: El script es idempotente — si las bases ya existen, no falla.
Cada CREATE DATABASE va envuelto en un IF NOT EXISTS para que
puedas re-ejecutar el script sin miedo.
============================================================================= */
USE master;
GO
-- ---------------------------------------------------------------------------
-- 1) Biblioteca Central — Ubicación A
-- ---------------------------------------------------------------------------
IF DB_ID('Biblioteca_Central') IS NULL
BEGIN
CREATE DATABASE Biblioteca_Central;
PRINT 'Base Biblioteca_Central creada.';
END
ELSE
PRINT 'Base Biblioteca_Central ya existe — se omite.';
GO
-- ---------------------------------------------------------------------------
-- 2) Biblioteca Norte — Ubicación B
-- ---------------------------------------------------------------------------
IF DB_ID('Biblioteca_Norte') IS NULL
BEGIN
CREATE DATABASE Biblioteca_Norte;
PRINT 'Base Biblioteca_Norte creada.';
END
ELSE
PRINT 'Base Biblioteca_Norte ya existe — se omite.';
GO
-- ---------------------------------------------------------------------------
-- 3) Biblioteca Sur — Ubicación C
-- ---------------------------------------------------------------------------
IF DB_ID('Biblioteca_Sur') IS NULL
BEGIN
CREATE DATABASE Biblioteca_Sur;
PRINT 'Base Biblioteca_Sur creada.';
END
ELSE
PRINT 'Base Biblioteca_Sur ya existe — se omite.';
GO
-- Verificación visual: lista las 3 bases recién creadas.
SELECT name AS base_de_datos, create_date AS fecha_creacion
FROM sys.databases
WHERE name IN ('Biblioteca_Central', 'Biblioteca_Norte', 'Biblioteca_Sur')
ORDER BY name;
GO