Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How to create a script to change content of a table

Posted on 2005-04-30
11
Medium Priority
?
173 Views
Last Modified: 2012-03-15
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
Comment
Question by:rfr1tz
11 Comments
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 800 total points
ID: 13901973
>>especiallly with Enterprise Manager utility.<<
In order to write T-SQL script you should use SQL Query Analyzer.
0
 
LVL 3

Assisted Solution

by:r_a_j_e_s_h
r_a_j_e_s_h earned 200 total points
ID: 13903710
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
 
LVL 19

Expert Comment

by:Melih SARICA
ID: 13904744
Wot kinda script  r u talking about ?

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

0
Free recovery tool for Microsoft Active Directory

Veeam Explorer for Microsoft Active Directory provides fast and reliable object-level recovery for Active Directory from a single-pass, agentless backup or storage snapshot — without the need to restore an entire virtual machine or use third-party tools.

 
LVL 3

Author Comment

by:rfr1tz
ID: 13905171
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
 
LVL 3

Author Comment

by:rfr1tz
ID: 13905180
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
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 13905365
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
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 13905370
You can also save the script using File | Save or Ctrl+S
0
 
LVL 3

Author Comment

by:rfr1tz
ID: 13905423
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
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 13905433
You can do it from SQL Query Analyzer.  Use Query | Execute or F5 (also Ctrl+E)
0
 
LVL 3

Author Comment

by:rfr1tz
ID: 13905610
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
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 13905683
>>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

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Suggested Courses

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question