Tuesday, August 8, 2017

JSon examples for product

[{
 _id : 1,
 title :"Neverwhere",
 author : "Neil, Gaimen",
 isbn : "43294239023430",
 genre : "fantasy",
 copyright : "1994",
 description : "a man gets lost in the London Underground and meets fantastic creatures."
},
{
  _id : 2,
  title : "2017 Hugo Award Winners",
  author : ["Liu", "Gaimen", "Moffit"],
  isbn : "3489349890",
  genre: "Science Fiction",
  copyright : "2017",
  description : "Hugo award winners"
}]


 

Collections for showTracker database

  • shows
  • venues
  • artists
  • fans
  • genres

Sample JSON for shows collection

{
   _id : 1,
   artist : "Hope Sandoval",
   ageRestriction : "21",
   venuename : "Showbox Market",
   showdate : "8/20/2017",
   showtime : "8:00 PM",
   price : 25.50
   
}

Links to Open source databases

http://blog.capterra.com/free-database-software/
  https://www.postgresql.org/about/
    https://firebirdsql.org
  http://www.itworld.com/article/2827484/enterprise-software/six-free-open-source-databases-with-commercial-quality-features.html
https://mariadb.com
  http://www.cubrid.org/

Thursday, August 3, 2017

MySQL SQL

use pythonclub2;
Select * from announcements;

Create user memberUser; 

Select * From MeetingNotes;

Select meetingsDate, MeetingTime, PlaceName, Meetingminutes
From meetings
inner join meetingnotes
on meetings.idMeetings=meetingnotes.Meetings_idMeetings
inner join places
on places.idPlaces=meetings.Places_idPlaces
Where MeetingsDate = '2017-06-21';

Insert into meetings(idMeetings, MeetingsDate, 
MeetingTime, Places_idPlaces)
Values(4,'2017-8-3','20:00:00',1);

Insert into Meetingnotes(idMeetingNotes, 
Meetings_idMeetings, MeetingMinutes)
values(4,4,'This meeting hasn''t happened yet');

Select * from Resources;

Update Resources
Set ResourcesName='John''s web Tutorial'
where idResources=1

Metro Alt Data Warehouse

Use master
/*Dimension Bus, BusRoute, Employee, Schedule,
Date, Fact schedule
*/
go
if exists
   (Select name from sys.Databases
      Where name = 'MetroAltDW')
    Begin
   Drop Database MetroAltDW
 end
Go
Create Database MetroAltDW
Go
use MetroAltDw
Go
Create table DimEmployee
(
   DimEmployeeKey int identity(1,1),
   EmployeeKey int,
   PositionKey int,
   PositionName nvarchar(255),
   EmployeeHireDate Date,
   EmployeeHourlyPayRate decimal(5,2)
)
Go
Create table DimBus
(
   DimBusKey int identity(1,1),
   BusKey int,
   BusTypeKey int,
   BustypeDescription nvarchar(255),
   BusTypePurchasePrice decimal(12,2)
)
go
Create table DimRoute
(
  DimrouteKey int identity(1,1),
  RouteKey int,
  BusRouteZone nvarchar(255)
)
Go
Create table DimSchedule
(
    DimScheduleKey int identity(1,1),
 BusDriverShiftKey int,
 BusScheduleAssignmentKey int,
 Employeekey int
)
go
Create table DimDate
(
     DimDateKey int identity(1,1),
  BusScheduleAssignmentDate date,
  BusScheduleYear int,
  BusScheduleMonth int
)
go
Create table FactSchedule
(
     DimEmployeeKey int not null,
  DimBusKey int not null,
  DimrouteKey int not null,
  DimScheduleKey int not null,
  DimDateKey int not null,
  Riders int,
  FaresPerRoute money
)
go

Alter table DimEmployee
Add constraint pk_DimEmployee primary key (DimEmployeeKey)

Alter table DimBus
Add constraint pk_DimBus primary key (DimBusKey)

Alter table Dimroute
Add constraint pk_DimRoute primary key (DimRouteKey)

Alter table DimSchedule
Add constraint pk_DimSchedule primary key (DimScheduleKey)

Alter table DimDate
Add constraint pk_DimDate primary key (DimDateKey)

Alter table FactSchedule
Add constraint pk_FactSchedule 
primary key (DimEmployeeKey, DimBusKey, 
DimRouteKey, DimScheduleKey, DimDateKey)

Alter table factSchedule
add constraint fk_DimEmployee foreign key (DimEmployeeKey)
   References DimEmployee(DimEmployeeKey)

Alter table factSchedule
add constraint fk_DimBus foreign key (DimbusKey)
   References DimBus(DimBusKey)

Alter table factSchedule
add constraint fk_DimRoute foreign key (DimRouteKey)
   References DimRoute(DimRouteKey)

Alter table factSchedule
add constraint fk_Schedule foreign key (DimScheduleKey)
   References DimSchedule(DimScheduleKey)

Alter table factSchedule
add constraint fk_DimDate foreign key (DimDateKey)
   References DimDate(DimDateKey)

   Insert into DimEmployee(EmployeeKey, PositionKey, 
   PositionName, EmployeeHireDate, EmployeeHourlyPayRate)
   Select e.EmployeeKey, p.PositionKey, 
   PositionName, EmployeeHireDate, EmployeeHourlyPayRate
   From MetroAlt.dbo.Employee e
   inner join MetroAlt.dbo.EmployeePosition ep
   on e.EmployeeKey=ep.EmployeeKey
   inner join MetroAlt.dbo.Position p
   on p.PositionKey=ep.PositionKey

  Insert into DimBus(BusKey, BusTypeKey, 
  BustypeDescription, BusTypePurchasePrice)
  Select b.BusKey, bt.BusTypeKey, 
  BustypeDescription, BusTypePurchasePrice
  From MetroAlt.dbo.Bus b
  inner join MetroAlt.dbo.Bustype bt
  on b.BusTypekey=bt.BusTypeKey

 Insert into Dimroute(RouteKey, BusRouteZone)
 Select BusRouteKey, BusRouteZone
 From MetroAlt.dbo.BusRoute

 Insert into dimSchedule(BusDriverShiftKey, 
 BusScheduleAssignmentKey, 
 Employeekey)
 Select BusDriverShiftKey, 
 BusScheduleAssignmentKey, 
 Employeekey
 From MetroAlt.dbo.BusScheduleAssignment

 Insert into DimDate(BusScheduleAssignmentDate, 
 BusScheduleYear, BusScheduleMonth)
 Select distinct BusScheduleAssignmentDate, 
 Year(BusScheduleAssignmentDate),
 Month(BusScheduleAssignmentDate)
 From Metroalt.dbo.BusScheduleAssignment

 Insert into FactSchedule(DimEmployeeKey, 
 DimBusKey, DimrouteKey, DimScheduleKey, 
 DimDateKey, Riders, FaresPerRoute)
 Select Distinct DimEmployeeKey, 
 DimBusKey, DimrouteKey, DimScheduleKey, 
 DimDateKey, Riders, Riders * FareAmount
 From MetroAlt.Dbo.BusScheduleAssignment bsa
 inner join DimEmployee de
 on de.EmployeeKey=bsa.EmployeeKey
 inner join dimBus db
 on db.BusKey=bsa.BusKey
 inner join Dimroute dr
 on dr.RouteKey=bsa.BusRouteKey
 inner join DimSchedule ds
 on ds.BusScheduleAssignmentKey=bsa.BusScheduleAssignmentKey
 inner join DimDate dd
 on dd.BusScheduleAssignmentDate=bsa.BusScheduleAssignmentDate
 inner join MetroAlt.dbo.Ridership r
 on r.BusScheduleAssigmentKey=bsa.BusScheduleAssignmentKey
 inner join MetroAlt.dbo.Fare f
 on f.FareKey=r.FareKey 

/*
Insert into FactSchedule(DimEmployeeKey, DimBusKey, DimRouteKey, DimScheduleKey, DimdateKey, riders, FaresPerRoute)
Select Distinct DimEmployeeKey, DimBusKey, DimRouteKey, DimScheduleKey, DimdateKey, riders, FareAmount * riders 
From MetroAlt.dbo.BusScheduleAssignment bsa
inner join DimEmployee de
on de.EmployeeKey=bsa.EmployeeKey
inner join dimBus db
on bsa.BusKey=db.BusKey
inner join dimRoute dr
on dr.RouteKey=bsa.BusRouteKey
inner join DimSchedule ds
on ds.busScheduleAssignmentKey=bsa.BusScheduleAssignmentKey
inner join dimDate dd
on dd.BusScheduleAssignmentDate=bsa.BusScheduleAssignmentDate
inner join MetroAlt.dbo.Ridership r
on r.BusScheduleAssigmentKey=bsa.BusScheduleAssignmentKey?*
inner join MetroAlt.dbo.fare f
on f.FareKey =r.FareKey

Tuesday, August 1, 2017

Full text Catalogs

Use Master
Create Database FullTextExample

Alter Database FullTextExample
Add FileGroup FullTextCatalog

use FulltextExample

Create Table TextTable
(
    TextTableKey int identity(1,1) primary key,
 TextExample nvarchar(255)
)

Insert into TextTable(TextExample)
Values('For test to be successful we must have a lot of text'),
('The test was not successful. sad face'),
('there is more than one test that can try a man'),
('Success is a relative term'),
('It is a rare man that is always successful'),
('The root of satisfaction is sad'),
('men want success'),
('We successfully completed the test'),
('Sadly, the test was difficult')

Insert into TextTable(TextExample)
Values('Best not to rest on ones successes'),
('The test is complete')

 
Create fulltext catalog TestDescription
on FileGroup FullTextCatalog

Create Fulltext index on TextTable(TextExample)
Key index [PK__TextTabl__B25F440D6815A9C6]
on TestDescription
with change_tracking auto

Select textTableKey, TextExample from TextTable
Where Freetext(textExample, 'sad')

Select TexttableKey, TextExample 
From TextTable
Where FreeText(TextExample, 'successful')

Select TextTableKey, TextExample
From TextTable
Where Contains(TextExample, '"success"')

Select TextTableKey, TextExample
From TextTable
Where Contains(TextExample, '"success*"')

Select TextTableKey, TextExample
From TextTable
Where Contains(TextExample, ' Formsof (Inflectional, Man)')

Select TextTableKey, TextExample
From TextTable
Where Contains(TextExample, ' Formsof (Inflectional, Complete)')

Select TextTableKey, TextExample
From TextTable
Where Contains(TextExample, ' near (try, man)')

Select TextTableKey, TextExample
From TextTable
Where Contains(TextExample, ' near ((man, successful), 2)')

select * from sys.dm_fts_index_keywords (db_id(),object_id('TextTable'))
order by Document_count desc