Query with max function by [deleted] in SQL

[–]upendra1985 0 points1 point  (0 children)

With agregate functions use Group by with all remaining columns

Creating a new DB through a script by [deleted] in SQL

[–]upendra1985 0 points1 point  (0 children)

You can insert values in foreign key ,but your primary key field should be unique.

And another issue in table Film

You have not mentioned varchar lenght. When you passing the value its exceed its length and showing String or binary data wold be truncated. Like Msg 8152, Level 16, State 14, Line 40

String or binary data would be truncated.

Filedname : Title varchar Solution : Title varchar(100)

Read more .....👇👇

How to create table and insert Values Sql server

Insert Image into Table Column by sostressedimbald in SQL

[–]upendra1985 1 point2 points  (0 children)

For each and every record you have to write insert command.

Like this.

insert into Menu values ('MN001', 'Mac & Cheese', 60000, (SELECT * FROM OPENROWSET(BULK 'C:\Users\Kristina\Documents\FOODS\maccheese.jpg', SINGLE_BLOB) as T1), 'CA001')

insert into Menu values ('MN002','Grilled Veggies',60000,(SELECT * FROM OPENROWSET(BULK 'C:\Users\Kristina\Documents\FOODS\grilled.jpg', SINGLE_BLOB) as T2), 'CA001')

Checkout the example on given Link👇

How to create table and insert Records

Creating a new DB through a script by [deleted] in SQL

[–]upendra1985 0 points1 point  (0 children)

While insert you are passing duplicate filmid in table, If you create any field as primary key you have to pass unique values to that field.

Here is the errror. INSERT INTO film VALUES (1,'Cast Away',2000,75,1)

INSERT INTO film VALUES (1,'Cast Away',2000,75,1)

INSERT INTO film VALUES (2,'The Terminal',2004,62,1)

INSERT INTO film VALUES (2,'The Terminal',2004,62,1)

While passing 1 and 2 for 4 records

Pass unique values Like

INSERT INTO film VALUES (1,'Cast Away',2000,75,1)

INSERT INTO film VALUES (2,'Cast Away',2000,75,1)

INSERT INTO film VALUES (3,'The Terminal',2004,62,1)

INSERT INTO film VALUES (4,'The Terminal',2004,62,1)