question

rhalld38 avatar image
rhalld38 asked

How do I add data to a table?

I have another homework question for my Movie database for college, how do I add data into a table? I hope I asked that question correctly. My teacher wants to see 10 records next week for a grade. The tables are Genre, Movies, Actor, Movie Rating,and Directors. I have two junction tables which are Movie Actors and Movie Directors that she wants to see in data in. Thanks for the help.
homework
5 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

WilliamD avatar image WilliamD commented ·
How about you give us what you have got so far and we will try to help. After all, this is your howmework - we can help, we won't do it all for you.
1 Like 1 ·
Matt Whitfield avatar image Matt Whitfield ♦♦ commented ·
Have you tried googling for 'how to insert data into sql server table'?
1 Like 1 ·
DaniSQL avatar image DaniSQL commented ·
@Matt, do you mean this:-) [ http://tinyurl.com/284k5pp][1] [1]: http://tinyurl.com/284k5pp
0 Likes 0 ·
Matt Whitfield avatar image Matt Whitfield ♦♦ commented ·
@DaniSQL - yes - although it would be much more impressive if they emulated google instant with that now! :)
0 Likes 0 ·
Scot Hauder avatar image Scot Hauder commented ·
0 Likes 0 ·
aRookieBIdev avatar image
aRookieBIdev answered
Try to create the records in an excel. say in columns a1, b1, c1 and d1. The in another column say g1 write a concatenate excel formula something like =CONCATENATE("INSERT INTO TableName (Column1, column2, column3, column4) VALUES(",A1,",",B1,",",C1,",",D1,")") then drag this according to the number of rows of data you have to generate the data insert scripts for the table.For string values pls concatenate double quotes before and after the value. Note if you include dollar in cellnames like $A$1 then the cell will always point to a1 cell even if you drag them.Also be careful about identity columns when you are doing an insert. There are many methods to do an insert quickly, this is something I do frequently. Using an Import and export wizard makes life even more easier.All you need is to configure the input and output.You could try that option as well. Thanks, Kannan
3 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Fatherjack avatar image Fatherjack ♦♦ commented ·
@Kannan - I think @rhalld38 is working on a TSQL section in a college course. Using Import/Export wizards is unlikely to get him a grade. I would assume the tutor is expecting to see a hand-written section of TSQL code. In homework cases on this site we try not to give out an exact answer as a big part of learning a topic is going through the stages of getting it wrong and then making it work. We will guide someone to the write answer but want to make sure they are committed to making an effort too.
3 Likes 3 ·
Fatherjack avatar image Fatherjack ♦♦ commented ·
@Kannan - no problem, I just didn't want you to up someone's grade and not get the credit! ;) We are always pleased to have enthusiasm here. Hope to see you around.
1 Like 1 ·
aRookieBIdev avatar image aRookieBIdev commented ·
opps sorry I am so unaware of this.I am a newbie here myself.Just being a lil over enthusiastic.. :D
0 Likes 0 ·
Fatherjack avatar image
Fatherjack answered
OK, so, the first clue I would offer is that you should reword your situation and say that you want to insert data into your table...
2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Fatherjack avatar image Fatherjack ♦♦ commented ·
where have you looked on how to insert data? If you havent already been looking in Books OnLine then I would suggest that you follow this link and search in the version that matches the SQL version you are using. http://technet.microsoft.com/en-gb/library/bb545450.aspx
2 Likes 2 ·
rhalld38 avatar image rhalld38 commented ·
So in the movies table how do I 'insert' data such as the movie Tears of the Sun? Thanks for the homework help, I don't expect someone to do this for me of course.
0 Likes 0 ·
Grant Fritchey avatar image
Grant Fritchey answered
Check out the word INSERT in the SQL Server Books Online, or search for '"SQL Server" T-SQL INSERT' in Google or Bing. That should get you started.
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

TimothyAWiseman avatar image
TimothyAWiseman answered
First, let me concur with Grant that your best bet is to look up the word "Insert" in an appropriate reference. But let me just add that in SQL, as in most things in programming, there are many ways to achieve the same goal. Kannan has already mentioned one, you can also open the table in SSMS for a GUI (though there are so many issues with this technique that I only ever use it to put data into a very small test table), BCP, BULK INSERT, etc. In short, when you are ready to get to that point just be aware that there are a lot of places to look. But just start with "Insert" like Grant said.
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Grant Fritchey avatar image Grant Fritchey ♦♦ commented ·
+1 Absolutely.
0 Likes 0 ·
Scot Hauder avatar image
Scot Hauder answered
I assume you know how to use the INSERT statement, but what you really want to know is how do I make sense of these junction tables? Generally it is easier to join these tables if you have a surrogate key column in the Genre, Movie and Actor tables. This can be implemented by adding a monotonically increasing number column with the IDENTITY keyword when creating the table eg CREATE TABLE Movie(MovieID int Identity, MovieName varchar(50)) Do the same with Genre and Actor. The join tables could then take the form CREATE TABLE MovieActor(MovieID int, ActorID int) So that a row in MovieActor such as (1,3) would link the 3rd Actor in your Actor table to the 1st Movie.
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.