Search code examples
sql-server-2008-express

How do I insert a Date and Image into my table?


CREATE TABLE Kitaplar
(
Id INT NOT NULL,
Isim NVARCHAR(50) NOT NULL,
Yazar NVARCHAR(50) NOT NULL,
Resim IMAGE,
Alinis_Tarihi DATE,
Verilis_Tarihi DATE,
PRIMARY KEY (Id)
)

I have this table and I want to create an instance.

insert into Kitaplar values 
  (003, 'Forty Thorns','Judy Lighy Ayyildiz',null,2012-01-01,2012-02-01)

it doesn't accept these date types.

How should I insert that? And how can I add an image?

I'm using SQL Server 2008 Express.


Solution

  • You need to enclose the dates in quotes as follows:

    Insert into Kitaplar values (003, 'Forty Thorns','Judy Lighy Ayyildiz',null,'2012-01-01','2012-02-01')
    

    As far as adding the image, something like this would work (there are other ways to do this too):

    Update myTable
    Set Image = (SELECT *
       FROM OPENROWSET(BULK N'C:\MyImage.jpg', SINGLE_BLOB) test)
       Where MyColumn = TargetValue