I am trying to extract values in a table called BOOK
. I have entered values in all tables that connect to BOOK
. When I run it I only get the first row (name of columns) but no value in the columns. Anyone here who can help?
CREATE VIEW GetBookData
AS
SELECT
BOOK.bookId,
BOOK.Title,
BOOK.pagecount,
Type.TypeName,
AUTHOR.AutherFirstName,
AUTHOR.AutherLastName
FROM BOOK
INNER JOIN AUTHOR ON BOOK.authorId = AUTHOR.authorId
INNER JOIN TYPE ON BOOK.typeId = TYPE.typeId
Select * from GetBookData
Here is my insert statements:
USE
RFID_Library
GO
INSERT INTO PERSON(PersonID, fName,lName,phone,email,dOB)
VALUES(123,'Ole', 'Hansen',98999400,'[email protected]', '2000/11/11')
--TESTVALUES BOOK---------------------------------
INSERT INTO BOOK(bookId,Title,pagecount)
VALUES(400,'Python',323)
INSERT INTO BOOK(bookId,Title,pagecount)
VALUES(401,'Snømannen',541)
INSERT INTO BOOK(bookId,Title,pagecount)
VALUES(402,'Elon Musk',401)
--TESTVALUES TYPE---------------------------------
INSERT INTO TYPE(typeId,TypeName)
VALUES(32,'Programmering')
INSERT INTO TYPE(typeId,TypeName)
VALUES(30,'Roman')
INSERT INTO TYPE(typeId,TypeName)
VALUES(31,'Biografi')
--TESTVALUES AUTHER---------------------------------
INSERT INTO AUTHOR(authorId, AutherFirstName, AutherLastName)
VALUES(1,'ole', 'Nordmann')
INSERT INTO AUTHOR(authorId, AutherFirstName, AutherLastName)
VALUES(2,'Nils', 'Hansen')
INSERT INTO AUTHOR(authorId, AutherFirstName, AutherLastName)
VALUES(3,'Herman', 'Pedersen')
UPDATE! here is my :
CREATE DATABASE RFID_Library
go
use
RFID_Library
go
CREATE TABLE AUTHOR
(
authorId integer NOT NULL ,
AutherFirstName char(40) NULL ,
AutherLastName char(40) NULL
)
go
CREATE TABLE BOOK
(
bookId integer NOT NULL ,
typeId integer NOT NULL ,
authorId integer NOT NULL ,
Title char(40) NULL ,
pagecount integer NULL
)
go
CREATE TABLE BORROW
(
borrowID char(40) NOT NULL ,
fromDate date NULL ,
toDate date NULL ,
bookId integer NOT NULL ,
PersonID integer NULL
)
go
CREATE TABLE PERSON
(
PersonID integer NOT NULL ,
fName char(40) NULL ,
lName char(40) NULL ,
phone integer NULL ,
email char(60) NULL ,
dOB date NULL
)
go
CREATE TABLE RFID
(
rfidId char(18) NOT NULL ,
fromDate date NULL ,
toDate date NULL ,
PersonID integer NOT NULL
)
go
CREATE TABLE TYPE
(
typeId integer NOT NULL ,
TypeName char(40) NULL
)
go
CodePudding user response:
Either do a LEFT JOIN instead of the INNER JOIN if you want to see BOOK values
Or update the BOOK with TypeId and AuthorId values.
CodePudding user response:
What are you inserting as authorId and typeId in your insert statement when populating the book table? Seems to be empty