• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 178
  • Last Modified:

How to create a script to change content of a table

Hi

I'd lile to create a script to add content into a table.
I read the manual of MS SQL and contents in MSDN and try to look for how to do it. There are some sections on MSDN mentioning about the scripts but didn't discuss in details howto, especiallly with Enterprise Manager utility.

If you know how, please help.

Thanks,

Rfr1tz

0
rfr1tz
Asked:
rfr1tz
2 Solutions
 
Anthony PerkinsCommented:
>>especiallly with Enterprise Manager utility.<<
In order to write T-SQL script you should use SQL Query Analyzer.
0
 
r_a_j_e_s_hCommented:
From EnterPrise manager u can create script & u can modify the script.

Right Click on the database u can make the cahnge in the script,
GoTo "All Tasks" -----> "Generate SQL Script" ---------> a wizard will open which have three tabs named as "General", "Formatting ", "Options." these trhee will be helpful for u to edit the script.


0
 
Melih SARICAOwnerCommented:
Wot kinda script  r u talking about ?

VB Scripsts ? J Scripts ? TSQL Statements ? or wot ?

0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
rfr1tzAuthor Commented:
Hi all,

Thanks for the reply.
I'd like to create a SQL script that add rows into a new table, say Table A.
I could do it with indiviudal Transact-SQL commands of INSERT .... However, I want to put all these individual commands into a script and run it .

Rajesh, I already opened "Generate SQL Script" wizzrd with 3 tabs as you specified but I couldn't find how to enter the text for the script to create a new script, how to open an existing script to edit it. I tried many things (before sending this questions), may you give me more details or steps how to do it.

And then, how could I run the script?

Thanks,

Rfr1tz
0
 
rfr1tzAuthor Commented:
Hi all,

Again, I missed something in my previous comment.
acperkins, if I'd like to write the script with "SQL Query Analyzer", how can I do it?

Thanks,

Rfr1tz

0
 
Anthony PerkinsCommented:
Just write all your insert statements one after the other:

INSERT TableA (Column1, Column2, Column3) VALUES ('Value11', 'Value12', 'Value13')
INSERT TableA (Column1, Column2, Column3) VALUES ('Value21', 'Value22', 'Value23')
INSERT TableA (Column1, Column2, Column3) VALUES ('Value31', 'Value32', 'Value33')
...

and execute.
0
 
Anthony PerkinsCommented:
You can also save the script using File | Save or Ctrl+S
0
 
rfr1tzAuthor Commented:
Hi acperkins,

Thanks a lot for the info.
About "execute" the ".sql" script files, do I need to open a DOS prompt? What I need to do to execute this script?

Thanks

Rfr1tz

0
 
Anthony PerkinsCommented:
You can do it from SQL Query Analyzer.  Use Query | Execute or F5 (also Ctrl+E)
0
 
rfr1tzAuthor Commented:
Hi acperkin,

For examples. I've created a database, named DB1, inside DB1, I've created a table T1.
Now, I'd like to insert new rows into the table T1 and I'd like to write the script for these statments.

As suggested above: INSERT T1 (col1, ...) VALUES (val1, ...)

In the script, should I write something else to specify that T1 is a table belongs to the database DB1, not another Database, for examples DB2?

Thanks,

Rfr1tz

0
 
Anthony PerkinsCommented:
>>In the script, should I write something else to specify that T1 is a table belongs to the database DB1<<
It depends.  If the current database is DB1 than you do not need to.  On the other hand, if you want to be sure you can set it explcitly as follows:

Use DB1
INSERT T1 (col1, ...) VALUES (val1, ...)
-- etc.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now