0

I am trying making a test on how to add multiple values into a column, which accepts multiple values.

For example, I have two tables

Table 1: contains `ID` (`int`) primary, `Name` (`varchar`)
Table 2: contains `ID` (reference to Table 1's `ID`), `Image` (`image`)

I created these tables, and I can insert data into table one, but how can I let it insert into multiple value column in table 2 (Image)?

I can have Id and add images how much I want, I tried with stored procedure, using insert, but failed, because I want to check ID is the same to ID in table 1 using where statement not working in insert

For more examples.

ID: 1, Name: Willam, Image:[AnyImage] (More than 1 image)
ID: 2, Name: Edi, Image[Anyknownimage], Image[AnyNewImage] etc...

Anything that helps?

Dai
  • 141,631
  • 28
  • 261
  • 374
Samer Yousef
  • 61
  • 1
  • 1
  • 8
  • Tag properly!!! MySQL <> SQL Server. Which one is this???? – Eric Jun 28 '18 at 22:46
  • Not Identity, it's about insert multiple values in same table – Samer Yousef Jun 28 '18 at 22:52
  • Why do you have Image in both tables? Image should not be in the 1st table. – jdweng Jun 28 '18 at 23:36
  • Alright, I changed it. – Samer Yousef Jun 28 '18 at 23:43
  • The `image` data types will be removed in a future version of SQL Server. Avoid using this data type in new development work, and plan to modify applications that currently use it. Use `varbinary(max)` instead. [See details here](http://msdn.microsoft.com/en-us/library/ms187993.aspx) – marc_s Jun 29 '18 at 04:18

1 Answers1

0

I think I've found a solution to my Question. The way I should do is to Set Identity_insert to on before insert and turn it off after insert in a procedure. Before the Set insert.

    CREATE proc [dbo].[Add_Image]
@ID int,
@Image image
as
Insert into ImageContainer(ID,Image) values(@ID,@Image)

After the altering the table to:

 CREATE proc [dbo].[Add_Image]
@ID int,
@Image image
as
SET IDENTITY_INSERT ImageContainer ON
Insert into ImageContainer(ID,Image) values(@ID,@Image)
SET IDENTITY_INSERT ImageContainer off

Thanks to you all

Samer Yousef
  • 61
  • 1
  • 1
  • 8