Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

SQL search by part of name

Voldyyy

New Coder
Can u help with this:
-find an item in the database by entering part of its name

SQL:
CREATE TABLE Confectionery (
IDConfect INT IDENTITY NOT NULL PRIMARY KEY,
NameProduct  NVARCHAR(50) NOT NULL,
Category INT NOT NULL,
Quantity SMALLINT NOT NULL,
Price DECIMAL(20)
);


CREATE TABLE ConfectioneryCategory (
IDConCat INT IDENTITY NOT NULL PRIMARY KEY,
CategoryName NVARCHAR(50) NOT NULL,
);


CREATE TABLE Sales (
SaleID INT IDENTITY NOT NULL,
Quantity INT NOT NULL,
DateOfSale DATE,
IDPastryChef INT NOT NULL,
IDProduct INT NOT NULL,
PRIMARY KEY(SaleID, IDProduct )
);


CREATE TABLE PastryChef (
IDPC INT IDENTITY NOT NULL PRIMARY KEY,
FirstName NVARCHAR(50),
LastName NVARCHAR(50),
ManifacturedProduct NVARCHAR(50)
);


ALTER TABLE Sales
ADD CONSTRAINT FK_Confectionery_Sales FOREIGN KEY (IDProduct)
REFERENCES Confectionery (IDConfect)
ON DELETE CASCADE
ON UPDATE CASCADE
;


ALTER TABLE Confectionery
ADD CONSTRAINT FK_Confectionery_ConfectioneryCategory FOREIGN KEY (Category)
REFERENCES ConfectioneryCategory (IDConCat)
ON DELETE CASCADE
ON UPDATE CASCADE
;


ALTER TABLE Sales
ADD CONSTRAINT FK_Sales_PastryChef FOREIGN KEY (IDPastryChef)
REFERENCES PastryChef (IDPC)
ON DELETE CASCADE
ON UPDATE CASCADE
;

INSERT INTO ConfectioneryCategory(CategoryName)
VALUES('deep fried'),('diabetic'),('cakes'),('crakers');

--deep fried
INSERT INTO Confectionery(NameProduct,Category,Quantity,Price )
VALUES('Donuts', 1, 50,'0.99');


INSERT INTO Confectionery(NameProduct,Category,Quantity,Price )
VALUES('Luqaimat', 1, 30 ,'4.12');


INSERT INTO Confectionery(NameProduct,Category,Quantity,Price )
VALUES('Tulumba', 1, 28 ,'1.25');


INSERT INTO Confectionery(NameProduct,Category,Quantity,Price )
VALUES('Julbia', 1, 15 ,'1.15');
 
Take a look at the MySQL LIKE operator:
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom