In SQL server I have two tables social_media_profile and tweets_info. The social
ID: 3707485 • Letter: I
Question
In SQL server I have two tables social_media_profile and tweets_info. The social_media_profile table has one column called SmID and it is the primary key. The tweets_info table has links, timestamp, and SmID columns, SmID is the foreign key. Using T-SQL, I need help with storing the links of each tweet or post, along with the time stamp. The link should be stored with the proper user id, in this case, the proper SmID. Each tweet/post and timestamp should have its own row. How do I do this?
This screenshot should provide some visual view of the type of data I am working with. Each tweet and timestamp should be matched to the proper profile.
Timestamp Your Twitter profile List of tweets/retweets 2102171142 07 i https://twitter.com/dummytweets/stat/3443503505030403024 2/10/2017 11:47:07 https://twitter com/dummyuser2000 https:/twitter.com/dummytweets/stat/3443503505030403024Explanation / Answer
Hi,
We'll start with T-SQL. T-SQL is nothing but extension of SQL language providing certain benefits in Transactions.
Transactions is nothing but performing multiple inserts or updates in the table and taking proper care of the data in case any operation fails and handling it.
According to the question, it requires us to insert tweet links along with the timestamp and the SmID should be one from the social_media_profile table only. So, we'll use the social_media_profile table to fetch us the correct SmID if it exists, and then use that result to insert the tweet in tweets_info.
**********************SQL QUERY***************************************
Select SmID from as 'SocialMediaID' from social_media_profile where SmID = 'dummyuser2000';
Begin TRANSACTION
INSERT INTO tweets_info (SmID, link, timestamp) values
SocialMediaID, 'https://twitter.com/dummyuser2000/tweets/1', '2/10/2017 11:47: 07' UNION ALL
SocialMediaID, 'https://twitter.com/dummyuser2000/tweets/2', '2/10/2017 11:47: 07'
COMMIT TRANSACTION
The union all operator ensures data entry into new rows everytime.
If there's anything else, post it in comments.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.