Last active
April 5, 2022 08:36
-
-
Save josemirm/c9946cda280e6eef3add34755efc7070 to your computer and use it in GitHub Desktop.
Crear base de datos de SQLite usando los archivos CSV disponibles
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Josemi Rodríguez | |
-- Script en SQL para convertir los ficheros "juridicas_1.csv", "juridicas_2.csv", y "convocatorias.csv" en una base de datos. | |
-- Uso: Se ejecuta "sqlite3 <nombre_base_datos>" y dentro de la interfaz de comandos de SQLite se escribe ".read crear_bd.sql" | |
-- La aplicación presupuestaria es una fecha con texto extra. | |
-- Por ejemplo "2022-03-3321-46203", cuando la fecha de concesión fue 24/03/2022 | |
create table juridicas( | |
id integer not null, | |
id_convocatoria integer not null, | |
administracion text not null, | |
departamento text not null, | |
organo text not null, | |
titulo_convocatoria text not null, | |
url_bases_regul text not null, | |
apli_presupuestaria text, | |
fecha_concesion date not null, | |
beneficiario text not null, | |
importe integer not null, | |
instrumento text not null, | |
ayuda_equivalente not null, | |
detalles text, | |
codigo_bdns integer not null, | |
valor_desconocido integer default 0, | |
id_interna integer primary key | |
); | |
create table convocatorias( | |
id integer not null, | |
codigo_bdns integer not null, | |
MRR text, | |
administracion text not null, | |
departamento text not null, | |
organo text not null, | |
fecha_registro date not null, | |
titulo_convocatoria text not null, | |
url_bases_regul text not null, | |
titulo_cooficial text, | |
colDesconocida1, | |
colDesconocida2, | |
colDesconocida3 | |
); | |
.mode csv | |
.import juridicas_1.csv juridicas | |
.import juridicas_2.csv juridicas | |
.import convocatorias.csv convocatorias |
Estoy preparado los "ficheros de formatos" para cargarlos con BCP en SQL Server...
Así es el de convocatorias...
<?xml version="1.0"?>
<BCPFORMAT xmlns="http://schemas.microsoft.com/sqlserver/2004/bulkload/format" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<RECORD>
<FIELD ID="1" xsi:type="CharTerm" TERMINATOR=',' />
<FIELD ID="2" xsi:type="CharTerm" TERMINATOR=','/>
<FIELD ID="3" xsi:type="CharTerm" TERMINATOR=','/>
<FIELD ID="4" xsi:type="CharTerm" TERMINATOR=','/>
<FIELD ID="5" xsi:type="CharTerm" TERMINATOR=','/>
<FIELD ID="6" xsi:type="CharTerm" TERMINATOR=','/>
<FIELD ID="7" xsi:type="CharTerm" TERMINATOR=','/>
<FIELD ID="8" xsi:type="CharTerm" TERMINATOR=','/>
<FIELD ID="9" xsi:type="CharTerm" TERMINATOR=','/>
<FIELD ID="10" xsi:type="CharTerm" TERMINATOR=','/>
<FIELD ID="11" xsi:type="CharTerm" TERMINATOR=','/>
<FIELD ID="12" xsi:type="CharTerm" TERMINATOR=','/>
<FIELD ID="13" xsi:type="CharTerm" TERMINATOR='\n'/>
</RECORD>
<ROW>
<COLUMN SOURCE="1" NAME="Id" xsi:type="SQLINT"/>
<COLUMN SOURCE="2" NAME="CodigoBDNS" xsi:type="SQLNVARCHAR" />
<COLUMN SOURCE="3" NAME="MRR" xsi:type="SQLNVARCHAR" />
<COLUMN SOURCE="4" NAME="Administracion" xsi:type="SQLNVARCHAR" />
<COLUMN SOURCE="5" NAME="Departamento" xsi:type="SQLNVARCHAR" />
<COLUMN SOURCE="6" NAME="Organo" xsi:type="SQLNVARCHAR" />
<COLUMN SOURCE="7" NAME="FechaRegistro" xsi:type="SQLNVARCHAR" />
<COLUMN SOURCE="8" NAME="TituloConvocatoria" xsi:type="SQLNVARCHAR" />
<COLUMN SOURCE="9" NAME="UrlBasesREgul" xsi:type="SQLNVARCHAR" />
<COLUMN SOURCE="10" NAME="TituloCooficial" xsi:type="SQLNVARCHAR" />
<COLUMN SOURCE="11" NAME="ColDesconocida1" xsi:type="SQLNVARCHAR" />
<COLUMN SOURCE="12" NAME="ColDesconocida2" xsi:type="SQLINT"/>
<COLUMN SOURCE="13" NAME="ColDesconocida3" xsi:type="SQLINT"/>
</ROW>
</BCPFORMAT>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hola,
¿De dónde has sacado el nombre de las columnas? ¿Sabemos seguro que son correctos?