Sunday, January 1, 2012

views vs. SOLR?

I'm trying to understand views and how to use views to solve the same problem SOLR solves. I'm also a little hung up. Some SQL I wrote:

BEGIN TRANSACTION

GO

CREATE TABLE dbo.Address

   (

   AddressId uniqueidentifier NOT NULL,

   StreetAddress varchar(255) NOT NULL

   ) ON [PRIMARY]

GO

ALTER TABLE dbo.Address ADD CONSTRAINT

   PK_Address PRIMARY KEY CLUSTERED

   (

   AddressId

   ) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF,

   ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

GO

ALTER TABLE dbo.Address SET (LOCK_ESCALATION = TABLE)

GO

COMMIT

BEGIN TRANSACTION

GO

CREATE TABLE dbo.Person

   (

   PersonId uniqueidentifier NOT NULL,

   Name varchar(255) NOT NULL,

   AddressId uniqueidentifier NOT NULL

   ) ON [PRIMARY]

GO

ALTER TABLE dbo.Person ADD CONSTRAINT

   PK_Person PRIMARY KEY CLUSTERED

   (

   PersonId

   ) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF,

   ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

GO

ALTER TABLE dbo.Person SET (LOCK_ESCALATION = TABLE)

GO

COMMIT

BEGIN TRANSACTION

GO

ALTER TABLE dbo.Person ADD CONSTRAINT

   FK_Person_Address FOREIGN KEY

   (

   AddressId

   ) REFERENCES dbo.Address

   (

   AddressId

   ) ON UPDATE NO ACTION

   ON DELETE NO ACTION

GO

COMMIT

INSERT INTO Address (AddressId, StreetAddress)

   Values ('58bfe64e-893a-44f0-b8d2-9e6a007bc0fa','123 Happy Street')

INSERT INTO Address (AddressId, StreetAddress)

   Values ('1ba51989-84fb-4a61-8c35-9e6a007bc0fb','456 Ace Avenue')

INSERT INTO Address (AddressId, StreetAddress)

   Values ('850cbe61-4535-4861-bb10-9e6a007bc102','77 Whatever Lane')

INSERT INTO Person (PersonId, Name, AddressId)

   Values ('90edbc51-b2b2-4d8d-915b-9e6a007bc0f9','Sally',

   '58bfe64e-893a-44f0-b8d2-9e6a007bc0fa')

INSERT INTO Person (PersonId, Name, AddressId)

   Values ('281872d1-4a1e-4d0c-8dc2-9e6a007bc101','Roy',

   '1ba51989-84fb-4a61-8c35-9e6a007bc0fb')

INSERT INTO Person (PersonId, Name, AddressId)

   Values ('71c2305a-da77-4dbf-842a-9e6a007bc0fe','Karl',

   '850cbe61-4535-4861-bb10-9e6a007bc102')

INSERT INTO Person (PersonId, Name, AddressId)

   Values ('73a15177-38af-495f-987f-9e6a007bc0fd','Nathan',

   '58bfe64e-893a-44f0-b8d2-9e6a007bc0fa')

BEGIN TRANSACTION

GO

CREATE VIEW PersonWithAddress

AS

SELECT dbo.Person.Name, dbo.Address.StreetAddress

FROM dbo.Person INNER JOIN

   dbo.Address ON dbo.Person.AddressId = dbo.Address.AddressId

GO

COMMIT

No comments:

Post a Comment