SQLTeam.com | Weblogs | Forums

Change Description


#1

Hi There,
A little help please.
I have a table with 64 rows and I need to change the description field of each row to a newly supplied value.
I cannot delete the table as it has a FK constraint.
How can I just import from a .csv / xls file and update / overwrite the description field.

Thanks for the help.

Best Regards,

Steve.


#2

You need to either update the column using the UPDATE command or you could create a new table based on the csv import using something like Bulk Insert or OpenRowset...

/* simple update */
USE MyDB
Go
UPDATE [dbo].[Books]
SET BookName = 'Donald Duck'
WHERE BookName = 'Bugs Bunny'


/* import sheet into new table with OPENROWSET */
USE MyDB
Go

SELECT * INTO MyNewTable
FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0',
                         'Excel 12.0 Xml;HDR=YES;Database=C:\testdata.xlsx;',
                         'SELECT * FROM [Sheet1$]')


/* Import into existing table with BULK INSERT*/

BULK INSERT #MyNewTable
FROM 'e:\testdata.csv'

WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)