| Author |
Topic |
|
New2SQL2
Starting Member
6 Posts |
Posted - 2008-05-21 : 17:00:17
|
Hi all,I am trying to insert some new rows into an existing SQL table. The table name is Agt_table, and I want to add some data for some new agents into existing columns:Agent name, agent code, phone number, fax numberExample - I want to add the following record to my existing table Agt_tableAgent name: ABC CompanyAgent code: 012345Phone #: 555-555-5555Fax#: 555-555-5555How would I write the sql statement to do that?Thanks so much!!!  |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-05-21 : 17:01:48
|
| INSERT INTO TableName (...)VALUES (...)Check SQL Server Books Online for details.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Database maintenance routines:http://weblogs.sqlteam.com/tarad/archive/2004/07/02/1705.aspx |
 |
|
|
New2SQL2
Starting Member
6 Posts |
Posted - 2008-05-21 : 17:04:05
|
I am SUPER new to SQL - can you show me exactly what I'd write for the example above?I really appreciate it! Thanks! |
 |
|
|
New2SQL2
Starting Member
6 Posts |
Posted - 2008-05-21 : 17:13:12
|
Can anyone else help me? |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-05-21 : 17:20:48
|
| Wouldn't you learn more if you looked it up or googled it?Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Database maintenance routines:http://weblogs.sqlteam.com/tarad/archive/2004/07/02/1705.aspx |
 |
|
|
New2SQL2
Starting Member
6 Posts |
Posted - 2008-05-21 : 17:24:58
|
| I have been looking for an hour and a half and can't seem to find anything. I literally just started using SQL yesterday, and a lot of what I read is way over my head. Believe me, I am trying to learn this! :) I am the only one in my office that is learning SQL, so I'm on my own.Any help would be greatly appreciated. Thanks so much. |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-05-21 : 17:27:19
|
| Here is an example:INSERT INTO Table1 (Column1, Column2)VALUES (1, 'Tara')Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Database maintenance routines:http://weblogs.sqlteam.com/tarad/archive/2004/07/02/1705.aspx |
 |
|
|
New2SQL2
Starting Member
6 Posts |
Posted - 2008-05-21 : 17:31:59
|
| So would this be right???INSERT INTO Agt_Table (Agent_Name, Agent_Code, Phone_, Fax_)VALUES ('ABC Company', '012345', '555-555-5555','555-555-5555')VALUES ('DEF Company', '456789', '555-123-4567, '555-123-4566')etc.Thank you so very much. |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-05-21 : 17:35:19
|
Not for MICROSOFT SQL Server.INSERT INTO Agt_Table (Agent_Name, Agent_Code, Phone_, Fax_)VALUES ('ABC Company', '012345', '555-555-5555','555-555-5555')INSERT INTO Agt_Table (Agent_Name, Agent_Code, Phone_, Fax_)VALUES ('DEF Company', '456789', '555-123-4567, '555-123-4566') E 12°55'05.25"N 56°04'39.16" |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-05-21 : 17:35:24
|
| For multiple rows, you can run INSERT INTO/VALUES multiple times per row or do this:INSERT INTO Table1 (Column1, Column2)SELECT 1, 'Tara' UNION ALLSELECT 2, 'Mike' UNION ALLSELECT 3, 'Andy'Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Database maintenance routines:http://weblogs.sqlteam.com/tarad/archive/2004/07/02/1705.aspx |
 |
|
|
New2SQL2
Starting Member
6 Posts |
Posted - 2008-05-21 : 17:39:49
|
I think I got it! Thanks so much Peso and Tara! |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-05-22 : 01:43:21
|
quote: Originally posted by Peso Not for MICROSOFT SQL Server.INSERT INTO Agt_Table (Agent_Name, Agent_Code, Phone_, Fax_)VALUES ('ABC Company', '012345', '555-555-5555','555-555-5555')INSERT INTO Agt_Table (Agent_Name, Agent_Code, Phone_, Fax_)VALUES ('DEF Company', '456789', '555-123-4567, '555-123-4566') E 12°55'05.25"N 56°04'39.16"
I heard this is possible in SQL 2008INSERT INTO Agt_Table (Agent_Name, Agent_Code, Phone_, Fax_)VALUES ('ABC Company', '012345', '555-555-5555','555-555-5555'),('DEF Company', '456789', '555-123-4567, '555-123-4566') |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-05-22 : 02:48:39
|
Yes it is. The difference in syntax is the comma between VALUES part. E 12°55'05.25"N 56°04'39.16" |
 |
|
|
|