Last active
April 27, 2019 18:16
-
-
Save rbatty19/f91fcfa5bfbe2feb15829e98e4f49195 to your computer and use it in GitHub Desktop.
SQL_SERVER_NOTES
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
CREATE TABLE investigadores ( | |
codigo int IDENTITY primary key, | |
nombre varchar(30), | |
ciudad varchar(30), | |
telefono varchar(30) | |
); | |
CREATE TABLE asignaciones ( | |
IDAsingacion int IDENTITY primary key, | |
codigo varchar(3), | |
id int, | |
tipo varchar(20) | |
); | |
CREATE TABLE proyectos ( | |
nombre varchar(50), | |
codigo varchar(3) primary key, | |
EntidadFinanciadora varchar(20), | |
FecInicio date, | |
FecFin date, | |
Presupuesto Numeric | |
); | |
INSERT INTO investigadores (nombre, ciudad, telefono) | |
VALUES | |
('FABIAN MARTINEZ', 'Cartagena', '6454545'), | |
('CARLOS MENDOZA', 'Barranquilla', '3122164'), | |
('MARIA LLERENA', 'Cartagena', '6489897'), | |
('DIANA LOPEZ', 'Cartagena', '6474849'), | |
('RICARDO PEREZ', 'Bogotá', '6678945'); | |
INSERT INTO proyectos | |
(nombre, codigo, EntidadFinanciadora, | |
FecInicio, FecFin, Presupuesto) | |
VALUES | |
('NEPTUNO', '001', 'COLCIENCIAS', | |
'01/02/2014', '31/10/2014', 560000000 ); | |
SELECT * | |
FROM investigadores AS i; | |
CREATE TABLE ciudades ( | |
id int IDENTITY primary key, | |
nombre varchar(30), | |
ciudad varchar(30) | |
); | |
--1 | |
SELECT codigo,nombre,presupuesto from proyectos WHERE EntidadFinanciadora = 'COLCIENCIAS' | |
--2 | |
SELECT * from proyectos WHERE Presupuesto >= 100 AND Presupuesto <= 500; | |
--3 | |
SELECT * from proyectos as p, investigadores as i, asignaciones as a | |
WHERE a.IDAsingacion = i.codigo and a.IDAsingacion = p.codigo and i.ciudad = 'cartagena' |
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
CREATE TABLE investigadores ( | |
codigo int IDENTITY primary key, | |
nombre varchar(30), | |
ciudad varchar(30), | |
telefono varchar(30) | |
); | |
CREATE TABLE asignaciones ( | |
IDAsingacion int IDENTITY primary key, | |
codigo varchar(3), | |
id int, | |
tipo varchar(20) | |
); | |
CREATE TABLE proyectos ( | |
nombre varchar(50), | |
codigo varchar(3) primary key, | |
EntidadFinanciadora varchar(20), | |
FecInicio date, | |
FecFin date, | |
Presupuesto Numeric | |
); | |
INSERT INTO investigadores (nombre, ciudad, telefono) | |
VALUES | |
('FABIAN MARTINEZ', 'Cartagena', '6454545'), | |
('CARLOS MENDOZA', 'Barranquilla', '3122164'), | |
('MARIA LLERENA', 'Cartagena', '6489897'), | |
('DIANA LOPEZ', 'Cartagena', '6474849'), | |
('RICARDO PEREZ', 'Bogotá', '6678945'); | |
INSERT INTO proyectos | |
(nombre, codigo, EntidadFinanciadora, | |
FecInicio, FecFin, Presupuesto) | |
VALUES | |
('NEPTUNO', '001', 'COLCIENCIAS', | |
'01/02/2014', '31/10/2014', 560000000 ); | |
SELECT * | |
FROM investigadores AS i; | |
CREATE TABLE ciudades ( | |
id int IDENTITY primary key, | |
nombre varchar(30), | |
ciudad varchar(30) | |
); | |
--1 | |
SELECT codigo,nombre,presupuesto from proyectos WHERE EntidadFinanciadora = 'COLCIENCIAS' | |
--2 | |
SELECT * from proyectos WHERE Presupuesto >= 100 AND Presupuesto <= 500; | |
--3 | |
SELECT * from proyectos as p, investigadores as i, asignaciones as a | |
WHERE a.IDAsingacion = i.codigo and a.IDAsingacion = p.codigo and i.ciudad = 'cartagena' | |
-- --------------------------- | |
Insert into ciudades (ciudad, nombre) values | |
('Cartagena','CTG'), | |
('Bogotá','BOG'); | |
INSERT INTO INVESTIGADORES ( nombre, ciudad,Telefono) | |
VALUES | |
( 'FABIAN MARTINEZ','CTG','6454545'), | |
( 'CARLOS MENDOZA','BAQ','3122164'), | |
( 'MARIA LLERENA','CTG','6489897'), | |
( 'DIANA LOPEZ','CTG','6474849'), | |
( 'RICARDO PEREZ','BAQ','6678945'); | |
select * from ciudades; | |
truncate table ciudades; | |
update ciudades set ciudad='Cartagena de Indias' where nombre = 'CTG'; | |
delete from ciudades where nombre = 'CTG'; | |
delete from ciudades where nombre = 'BOG'; | |
SELECT ciudad ,COUNT(*) FROM investigadores group by ciudad; |
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
USE [master] | |
GO | |
/****** Object: Database [taller] Script Date: 06/04/2019 2:16:45 p. m. ******/ | |
CREATE DATABASE [taller] | |
CONTAINMENT = NONE | |
ON PRIMARY | |
( NAME = N'taller', FILENAME = N'C:\ZeusData\Data\taller.mdf' , SIZE = 3072KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB ) | |
LOG ON | |
( NAME = N'taller_log', FILENAME = N'C:\ZeusData\Data\taller_log.ldf' , SIZE = 1024KB , MAXSIZE = 2048GB , FILEGROWTH = 10%) | |
GO | |
ALTER DATABASE [taller] SET COMPATIBILITY_LEVEL = 110 | |
GO | |
IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled')) | |
begin | |
EXEC [taller].[dbo].[sp_fulltext_database] @action = 'enable' | |
end | |
GO | |
ALTER DATABASE [taller] SET ANSI_NULL_DEFAULT OFF | |
GO | |
ALTER DATABASE [taller] SET ANSI_NULLS OFF | |
GO | |
ALTER DATABASE [taller] SET ANSI_PADDING OFF | |
GO | |
ALTER DATABASE [taller] SET ANSI_WARNINGS OFF | |
GO | |
ALTER DATABASE [taller] SET ARITHABORT OFF | |
GO | |
ALTER DATABASE [taller] SET AUTO_CLOSE OFF | |
GO | |
ALTER DATABASE [taller] SET AUTO_CREATE_STATISTICS ON | |
GO | |
ALTER DATABASE [taller] SET AUTO_SHRINK OFF | |
GO | |
ALTER DATABASE [taller] SET AUTO_UPDATE_STATISTICS ON | |
GO | |
ALTER DATABASE [taller] SET CURSOR_CLOSE_ON_COMMIT OFF | |
GO | |
ALTER DATABASE [taller] SET CURSOR_DEFAULT GLOBAL | |
GO | |
ALTER DATABASE [taller] SET CONCAT_NULL_YIELDS_NULL OFF | |
GO | |
ALTER DATABASE [taller] SET NUMERIC_ROUNDABORT OFF | |
GO | |
ALTER DATABASE [taller] SET QUOTED_IDENTIFIER OFF | |
GO | |
ALTER DATABASE [taller] SET RECURSIVE_TRIGGERS OFF | |
GO | |
ALTER DATABASE [taller] SET DISABLE_BROKER | |
GO | |
ALTER DATABASE [taller] SET AUTO_UPDATE_STATISTICS_ASYNC OFF | |
GO | |
ALTER DATABASE [taller] SET DATE_CORRELATION_OPTIMIZATION OFF | |
GO | |
ALTER DATABASE [taller] SET TRUSTWORTHY OFF | |
GO | |
ALTER DATABASE [taller] SET ALLOW_SNAPSHOT_ISOLATION OFF | |
GO | |
ALTER DATABASE [taller] SET PARAMETERIZATION SIMPLE | |
GO | |
ALTER DATABASE [taller] SET READ_COMMITTED_SNAPSHOT OFF | |
GO | |
ALTER DATABASE [taller] SET HONOR_BROKER_PRIORITY OFF | |
GO | |
ALTER DATABASE [taller] SET RECOVERY SIMPLE | |
GO | |
ALTER DATABASE [taller] SET MULTI_USER | |
GO | |
ALTER DATABASE [taller] SET PAGE_VERIFY CHECKSUM | |
GO | |
ALTER DATABASE [taller] SET DB_CHAINING OFF | |
GO | |
ALTER DATABASE [taller] SET FILESTREAM( NON_TRANSACTED_ACCESS = OFF ) | |
GO | |
ALTER DATABASE [taller] SET TARGET_RECOVERY_TIME = 0 SECONDS | |
GO | |
USE [taller] | |
GO | |
/****** Object: Table [dbo].[Asignaciones] Script Date: 06/04/2019 2:16:45 p. m. ******/ | |
SET ANSI_NULLS ON | |
GO | |
SET QUOTED_IDENTIFIER ON | |
GO | |
SET ANSI_PADDING ON | |
GO | |
CREATE TABLE [dbo].[Asignaciones]( | |
[IdAsignaciones] [int] IDENTITY(1,1) NOT NULL, | |
[CodProyecto] [varchar](3) NULL, | |
[CodInvestigador] [varchar](15) NULL, | |
[Tipo] [varchar](25) NULL, | |
CONSTRAINT [PK_Asignaciones] PRIMARY KEY CLUSTERED | |
( | |
[IdAsignaciones] ASC | |
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] | |
) ON [PRIMARY] | |
GO | |
SET ANSI_PADDING OFF | |
GO | |
/****** Object: Table [dbo].[Ciudades] Script Date: 06/04/2019 2:16:45 p. m. ******/ | |
SET ANSI_NULLS ON | |
GO | |
SET QUOTED_IDENTIFIER ON | |
GO | |
SET ANSI_PADDING ON | |
GO | |
CREATE TABLE [dbo].[Ciudades]( | |
[codCiudad] [varchar](3) NOT NULL, | |
[Nomciudad] [varchar](50) NULL, | |
CONSTRAINT [PK_Ciudades] PRIMARY KEY CLUSTERED | |
( | |
[codCiudad] ASC | |
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] | |
) ON [PRIMARY] | |
GO | |
SET ANSI_PADDING OFF | |
GO | |
/****** Object: Table [dbo].[Entidades] Script Date: 06/04/2019 2:16:45 p. m. ******/ | |
SET ANSI_NULLS ON | |
GO | |
SET QUOTED_IDENTIFIER ON | |
GO | |
SET ANSI_PADDING ON | |
GO | |
CREATE TABLE [dbo].[Entidades]( | |
[CodEntidades] [varchar](3) NOT NULL, | |
[NomEntidad] [varchar](50) NULL, | |
CONSTRAINT [PK_Entidades] PRIMARY KEY CLUSTERED | |
( | |
[CodEntidades] ASC | |
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] | |
) ON [PRIMARY] | |
GO | |
SET ANSI_PADDING OFF | |
GO | |
/****** Object: Table [dbo].[Investigadores] Script Date: 06/04/2019 2:16:45 p. m. ******/ | |
SET ANSI_NULLS ON | |
GO | |
SET QUOTED_IDENTIFIER ON | |
GO | |
SET ANSI_PADDING ON | |
GO | |
CREATE TABLE [dbo].[Investigadores]( | |
[CodInvestigador] [varchar](15) NOT NULL, | |
[NomInvestigador] [varchar](50) NULL, | |
[CodCiudad] [varchar](3) NULL, | |
[Telefono] [varchar](15) NULL, | |
CONSTRAINT [PK_Investigadores] PRIMARY KEY CLUSTERED | |
( | |
[CodInvestigador] ASC | |
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] | |
) ON [PRIMARY] | |
GO | |
SET ANSI_PADDING OFF | |
GO | |
/****** Object: Table [dbo].[Proyectos] Script Date: 06/04/2019 2:16:45 p. m. ******/ | |
SET ANSI_NULLS ON | |
GO | |
SET QUOTED_IDENTIFIER ON | |
GO | |
SET ANSI_PADDING ON | |
GO | |
CREATE TABLE [dbo].[Proyectos]( | |
[CodProyecto] [varchar](3) NOT NULL, | |
[NomProyecto] [varchar](20) NULL, | |
[CodEntidad] [varchar](3) NULL, | |
[FecInicio] [date] NULL, | |
[FecFin] [date] NULL, | |
[Presupuesto] [varchar](15) NULL, | |
CONSTRAINT [PK_Proyectos] PRIMARY KEY CLUSTERED | |
( | |
[CodProyecto] ASC | |
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] | |
) ON [PRIMARY] | |
GO | |
SET ANSI_PADDING OFF | |
GO | |
ALTER TABLE [dbo].[Asignaciones] WITH CHECK ADD CONSTRAINT [FK_Asignaciones_Investigadores] FOREIGN KEY([CodInvestigador]) | |
REFERENCES [dbo].[Investigadores] ([CodInvestigador]) | |
GO | |
ALTER TABLE [dbo].[Asignaciones] CHECK CONSTRAINT [FK_Asignaciones_Investigadores] | |
GO | |
ALTER TABLE [dbo].[Asignaciones] WITH CHECK ADD CONSTRAINT [FK_Asignaciones_Proyectos] FOREIGN KEY([CodProyecto]) | |
REFERENCES [dbo].[Proyectos] ([CodProyecto]) | |
GO | |
ALTER TABLE [dbo].[Asignaciones] CHECK CONSTRAINT [FK_Asignaciones_Proyectos] | |
GO | |
ALTER TABLE [dbo].[Investigadores] WITH CHECK ADD CONSTRAINT [FK_Investigadores_Ciudades] FOREIGN KEY([CodCiudad]) | |
REFERENCES [dbo].[Ciudades] ([codCiudad]) | |
GO | |
ALTER TABLE [dbo].[Investigadores] CHECK CONSTRAINT [FK_Investigadores_Ciudades] | |
GO | |
ALTER TABLE [dbo].[Proyectos] WITH CHECK ADD CONSTRAINT [FK_Proyectos_Entidades] FOREIGN KEY([CodEntidad]) | |
REFERENCES [dbo].[Entidades] ([CodEntidades]) | |
GO | |
ALTER TABLE [dbo].[Proyectos] CHECK CONSTRAINT [FK_Proyectos_Entidades] | |
GO | |
ALTER TABLE [dbo].[Proyectos] WITH CHECK ADD CONSTRAINT [FK_Proyectos_Entidades1] FOREIGN KEY([CodEntidad]) | |
REFERENCES [dbo].[Entidades] ([CodEntidades]) | |
GO | |
ALTER TABLE [dbo].[Proyectos] CHECK CONSTRAINT [FK_Proyectos_Entidades1] | |
GO | |
USE [master] | |
GO | |
ALTER DATABASE [taller] SET READ_WRITE | |
GO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment