| Author |
Topic  |
|
|
bsieloff
Starting Member
2 Posts |
Posted - 09/13/2007 : 13:49:01
|
Greetings,
I am new at SQL and I have been asked to load some data into a database. I was given a file that has an extention .sql. shown below are the first few lines
quote: TRUNCATE TABLE henrylee.[HenryLee] GO INSERT INTO henrylee.[HenryLee] ( [custno], [company], [address1], [address2], [city], [state], [zip], [phone], [email] ) VALUES ( 'C00001', 'SUPREME NOVELTY', '5954 S PULASKI ROAD', '', 'CHICAGO', 'IL', '60629', '', '' )
several more rows after this
This looks to me like it was built to be scripted in or use some function of SQL to create and populate the table... does that make sense? Anyway, is there an easy way to insert this data into a table?
Thanks -B
|
|
|
Kristen
Test
United Kingdom
22191 Posts |
Posted - 09/13/2007 : 13:52:13
|
"TRUNCATE TABLE henrylee.[HenryLee]"
This assumed that you have a database called "henrylee" and a table within that database called "HenryLee".
If you haven't then this script is about as much as a chocolate tea-pot 
You could globally find & replace henrylee.[HenryLee] with the name of your database / table. But if you don't already have a suitable table created then this won't be much use without one - you can't really guess what datatype / size / Primary key / etc. the original table had.
Kristen
|
 |
|
|
jen
Flowing Fount of Yak Knowledge
Sweden
4110 Posts |
Posted - 09/13/2007 : 13:52:13
|
unless it's in a csv file with only the data in it, no
that is the easiest, just open in ssms or QA and execute.. but i suggest you backup the table before executing it..
select * into henrylee.henrylee_backupdate from henrylee.henrylee
in case henrylee is fooling around with you 
-------------------- keeping it simple... |
 |
|
|
Kristen
Test
United Kingdom
22191 Posts |
Posted - 09/13/2007 : 14:07:15
|
I presume that "henrylee" is representative of the data it contains and follows your normal table-naming-conventions?  |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
bsieloff
Starting Member
2 Posts |
Posted - 09/13/2007 : 14:48:34
|
there is a database and table already created, and yes the name is henrylee. I'm not the designer just the maintenance boy ;-)
therefore you are saying I can; open management studio click on new query <type> exec c:\henrylee.sql click execute
and the data should be loaded correctly witht he way the file is written?
thanks for the help -B
|
 |
|
|
Kristen
Test
United Kingdom
22191 Posts |
Posted - 09/13/2007 : 14:51:32
|
"I'm not the designer just the maintenance boy"

It should be more like this:
Take backup! open management studio click on new query File Open c:\henrylee.sql click execute Check and Restore from backup if something-terrible-happened
Kristen |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
jen
Flowing Fount of Yak Knowledge
Sweden
4110 Posts |
Posted - 09/13/2007 : 15:16:17
|
no, if something wrong happens, you're the escape goat 
-------------------- keeping it simple... |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
Kristen
Test
United Kingdom
22191 Posts |
Posted - 09/13/2007 : 15:28:11
|
"BEGIN TRAN
DML
--ROLLBACK"
Although risky if there are any GO statements in the DML 
Kristen
|
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
Kristen
Test
United Kingdom
22191 Posts |
Posted - 09/13/2007 : 15:31:47
|
"Unlike Oracle"
Really? Well that would be good-to-have in SQL Server too ... |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
Kristen
Test
United Kingdom
22191 Posts |
Posted - 09/13/2007 : 16:07:56
|
"No, in Oracle, the trans is not committed until you specially say so."
And a syntax, or other terminal error, doesn't abort the transaction - leaving the rest of the statements outside a transaction block (and thus implicitly committed)?
Can't understand why SQL Server doesn't have that; very dangerous IMHO
Kristen |
 |
|
|
jen
Flowing Fount of Yak Knowledge
Sweden
4110 Posts |
Posted - 09/13/2007 : 16:18:59
|
yes very... an uncommitted transaction done on the 'right' tables will leaves the application (some parts) in hanged state... blocks even
-------------------- keeping it simple... |
 |
|
| |
Topic  |
|