Author |
Topic |
bsieloff
Starting Member
2 Posts |
Posted - 2007-09-13 : 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]GOINSERT 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
22859 Posts |
Posted - 2007-09-13 : 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 & replacehenrylee.[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
Master Smack Fu Yak Hacker
4110 Posts |
Posted - 2007-09-13 : 13:52:13
|
unless it's in a csv file with only the data in it, nothat 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_backupdatefrom henrylee.henryleein case henrylee is fooling around with you --------------------keeping it simple... |
|
|
Kristen
Test
22859 Posts |
Posted - 2007-09-13 : 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 - 2007-09-13 : 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 studioclick on new query<type> exec c:\henrylee.sql click executeand the data should be loaded correctly witht he way the file is written?thanks for the help-B |
|
|
Kristen
Test
22859 Posts |
Posted - 2007-09-13 : 14:51:32
|
"I'm not the designer just the maintenance boy"It should be more like this:Take backup!open management studioclick on new queryFile Open c:\henrylee.sqlclick executeCheck and Restore from backup if something-terrible-happenedKristen |
|
|
X002548
Not Just a Number
15586 Posts |
|
jen
Master Smack Fu Yak Hacker
4110 Posts |
Posted - 2007-09-13 : 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
22859 Posts |
Posted - 2007-09-13 : 15:28:11
|
"BEGIN TRANDML--ROLLBACK"Although risky if there are any GO statements in the DML Kristen |
|
|
X002548
Not Just a Number
15586 Posts |
|
Kristen
Test
22859 Posts |
Posted - 2007-09-13 : 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
22859 Posts |
Posted - 2007-09-13 : 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 IMHOKristen |
|
|
jen
Master Smack Fu Yak Hacker
4110 Posts |
Posted - 2007-09-13 : 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... |
|
|
|