Click here to Skip to main content
14,298,626 members
   

Database

 
AnswerRe: Hwere's a Head-Scratcher Pin
Richard Deeming28-Aug-19 10:00
mveRichard Deeming28-Aug-19 10:00 
GeneralRe: Hwere's a Head-Scratcher Pin
Mycroft Holmes28-Aug-19 12:42
memberMycroft Holmes28-Aug-19 12:42 
GeneralRe: Hwere's a Head-Scratcher Pin
#realJSOP28-Aug-19 23:23
mve#realJSOP28-Aug-19 23:23 
GeneralRe: Hwere's a Head-Scratcher Pin
Richard Deeming29-Aug-19 1:22
mveRichard Deeming29-Aug-19 1:22 
GeneralRe: Hwere's a Head-Scratcher Pin
#realJSOP29-Aug-19 1:47
mve#realJSOP29-Aug-19 1:47 
GeneralRe: Hwere's a Head-Scratcher Pin
Richard Deeming29-Aug-19 1:55
mveRichard Deeming29-Aug-19 1:55 
GeneralRe: Hwere's a Head-Scratcher Pin
#realJSOP29-Aug-19 1:59
mve#realJSOP29-Aug-19 1:59 
QuestionError With Simple Script Pin
Kevin Marois22-Aug-19 8:26
professionalKevin Marois22-Aug-19 8:26 
I'm trying to create a small sample database. Towards the bottom when I', inserting Book3, I suddenly get an FK violation from Books into Categories. Yet the caregory id is there.

Can someone try thnis and tell me wtf is wrong????
USE master
IF EXISTS(SELECT * FROM sys.databases WHERE Name = 'BookCatalog')
DROP DATABASE BookCatalog
Go
CREATE DATABASE BookCatalog
GO
USE [BookCatalog]
GO

CREATE TABLE [dbo].[BookCategories]
(
    [Id]        [INT] IDENTITY(1,1) PRIMARY KEY NOT NULL,
    [Name]      VARCHAR(MAX) NOT NULL,
)

CREATE TABLE [dbo].[Books]
(
    [Id]        [INT] IDENTITY(1,1) PRIMARY KEY NOT NULL,
    [Category]  [INT] NULL FOREIGN KEY (Id) REFERENCES BookCategories(Id),
    [Title]     VARCHAR(MAX) NOT NULL,
    [Price]     MONEY NULL
)

CREATE TABLE [dbo].[Authors]
(
    [Id]        [INT] IDENTITY(1,1) PRIMARY KEY NOT NULL,
    [Name]      VARCHAR(MAX) NOT NULL,
)

CREATE TABLE [dbo].[BookAuthors]
(
    [Id]        [INT] IDENTITY(1,1) PRIMARY KEY NOT NULL,
    [Book]      [INT] NULL FOREIGN KEY (Id) REFERENCES Books(Id),
    [Author]    [INT] NULL FOREIGN KEY (Id) REFERENCES Authors(Id),
)

GO
USE [BookCatalog]

-- Book Categories
DECLARE @CategoryId1 INT
INSERT INTO BookCategories (Name) VALUES ('C#')
SET @CategoryId1 = SCOPE_IDENTITY()

DECLARE @CategoryId2 INT
INSERT INTO BookCategories (Name) VALUES ('Programming Practices')
SET @CategoryId2 = SCOPE_IDENTITY()

-- Authors
DECLARE @MartinId INT
INSERT INTO Authors (Name) VALUES ('Bob Martin')
SET @MartinId = SCOPE_IDENTITY()

DECLARE @Albahari1Id INT
INSERT INTO Authors (Name) VALUES ('Joseph Albahari')
SET @Albahari1Id = SCOPE_IDENTITY()

DECLARE @Albahari2Id INT
INSERT INTO Authors (Name) VALUES ('Ben Albahari')
SET @Albahari2Id = SCOPE_IDENTITY()

DECLARE @WagnerId INT
INSERT INTO Authors (Name) VALUES ('Bill Wagner')
SET @WagnerId = SCOPE_IDENTITY()

DECLARE @SkeetId INT
INSERT INTO Authors (Name) VALUES ('Jon Skeet')
SET @SkeetId = SCOPE_IDENTITY()

-- Books
DECLARE @BookId1 INT
INSERT INTO Books (Category, Title, Price) VALUES (@CategoryId1, 'Agile Principles, Patterns, and Practices in C#', 64.99)
SET @BookId1 = SCOPE_IDENTITY()

DECLARE @BookId2 INT
INSERT INTO Books (Category, Title, Price) VALUES (@CategoryId2, 'C# 3.0 in a Nutshell', 34.99)
SET @BookId2 = SCOPE_IDENTITY()

DECLARE @BookId3 INT
INSERT INTO Books (Category, Title, Price) VALUES (@CategoryId2, 'C# Core Langaue: Little Black Book', 20.00)
SET @BookId3 = SCOPE_IDENTITY()

DECLARE @BookId4 INT
INSERT INTO Books (Category, Title, Price) VALUES (@CategoryId2, 'C# In Depth', 44.99)
SET @BookId4 = SCOPE_IDENTITY()

--Book-Authors
INSERT INTO BookAuthors (Book, Author) VALUES (@BookId1, @MartinId)
INSERT INTO BookAuthors (Book, Author) VALUES (@BookId2, @Albahari1Id)
INSERT INTO BookAuthors (Book, Author) VALUES (@BookId2, @Albahari2Id)
INSERT INTO BookAuthors (Book, Author) VALUES (@BookId3, @WagnerId)
INSERT INTO BookAuthors (Book, Author) VALUES (@BookId4, @SkeetId)
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.

AnswerRe: Error With Simple Script Pin
Richard Deeming23-Aug-19 1:08
mveRichard Deeming23-Aug-19 1:08 
GeneralRe: Error With Simple Script Pin
Kevin Marois23-Aug-19 6:21
professionalKevin Marois23-Aug-19 6:21 
QuestionAccess SQL Server Remotely Via VPN Pin
Kevin Marois20-Aug-19 5:40
professionalKevin Marois20-Aug-19 5:40 
AnswerRe: Access SQL Server Remotely Via VPN Pin
Richard Deeming20-Aug-19 5:56
mveRichard Deeming20-Aug-19 5:56 
QuestionSQL Remote Connection Problem Pin
Kevin Marois19-Aug-19 7:52
professionalKevin Marois19-Aug-19 7:52 
AnswerRe: SQL Remote Connection Problem Pin
Richard Deeming19-Aug-19 8:45
mveRichard Deeming19-Aug-19 8:45 
GeneralRe: SQL Remote Connection Problem Pin
Kevin Marois19-Aug-19 9:21
professionalKevin Marois19-Aug-19 9:21 
GeneralRe: SQL Remote Connection Problem Pin
Richard Deeming19-Aug-19 9:28
mveRichard Deeming19-Aug-19 9:28 
GeneralRe: SQL Remote Connection Problem Pin
Kevin Marois19-Aug-19 9:42
professionalKevin Marois19-Aug-19 9:42 
QuestionDate format in SQL Database export to Excel 23/01/1990 00:00:00 instat of 23/01/1990 Pin
jan Meeling18-Aug-19 22:15
memberjan Meeling18-Aug-19 22:15 
QuestionRe: Date format in SQL Database export to Excel 23/01/1990 00:00:00 instat of 23/01/1990 Pin
Richard MacCutchan18-Aug-19 22:54
protectorRichard MacCutchan18-Aug-19 22:54 
AnswerRe: Date format in SQL Database export to Excel 23/01/1990 00:00:00 instat of 23/01/1990 Pin
jan Meeling19-Aug-19 1:39
memberjan Meeling19-Aug-19 1:39 
GeneralRe: Date format in SQL Database export to Excel 23/01/1990 00:00:00 instat of 23/01/1990 Pin
Victor Nijegorodov19-Aug-19 3:20
memberVictor Nijegorodov19-Aug-19 3:20 
GeneralRe: Date format in SQL Database export to Excel 23/01/1990 00:00:00 instat of 23/01/1990 Pin
Richard MacCutchan19-Aug-19 4:23
protectorRichard MacCutchan19-Aug-19 4:23 
AnswerRe: Date format in SQL Database export to Excel 23/01/1990 00:00:00 instat of 23/01/1990 Pin
Victor Nijegorodov19-Aug-19 0:19
memberVictor Nijegorodov19-Aug-19 0:19 
GeneralRe: Date format in SQL Database export to Excel 23/01/1990 00:00:00 instat of 23/01/1990 Pin
jan Meeling19-Aug-19 1:43
memberjan Meeling19-Aug-19 1:43 
AnswerRe: Date format in SQL Database export to Excel 23/01/1990 00:00:00 instat of 23/01/1990 Pin
Eddy Vluggen19-Aug-19 1:12
mveEddy Vluggen19-Aug-19 1:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.