Write the DDL to construct the Facebook User and Post tables in SQL server.

Write the DDL to construct the Facebook User and Post tables in SQL server. You need to populate the user table with the user’s information provided as in Figure 1 and additional attributes may be needed for the design. Use the ID in the excel file to
identify the other Facebook user. For example ID 612831408762037 is David Cunliffe. Import the excel sheets to SQL server and then write effective SQL to merge the two tables into the Post table. Ensure the relationship is maintained between entities. Submit
the SQL scripts that create the database and tables, import the excel sheets and populate the tables such that one can re-create the database and tables with all the data by running the script.

IF NOT EXISTS(SELECT * FROM sys.databases WHERE name = N'xxx')
CREATE DATABASE xxx
GO
USE xxx
IF EXISTS(SELECT * FROM sys.tables WHERE name = N'DAVID') 
DROP TABLE DAVID;
IF EXISTS(SELECT * FROM sys.tables WHERE name = N'JOHN')
DROP TABLE JOHN;
IF EXISTS(SELECT * FROM sys.tables WHERE name = N'NEWDAVID') 
DROP TABLE NEWDAVID;
IF EXISTS(SELECT * FROM sys.tables WHERE name = N'NEWJOHN') 
DROP TABLE NEWJOHN;
IF EXISTS(SELECT * FROM sys.tables WHERE name = N'USER') 
DROP TABLE [USER];
IF EXISTS(SELECT * FROM sys.tables WHERE name = N'POST') 
DROP TABLE POST;
CREATE TABLE DAVID(
ID VARCHAR(100),
[MESSAGE] VARCHAR(MAX),
[TYPE] VARCHAR(MAX),
CREATED_TIME VARCHAR(MAX),
UPDATED_TIME VARCHAR(MAX),
SHARES_COUNT VARCHAR(MAX),
[COUNT OF LIKES NAME] VARCHAR(MAX),
[COUNT OF COMMENTS MESSAGE] VARCHAR(MAX),
LINK VARCHAR(MAX),
NAME VARCHAR(MAX),
[DESCRIPTION] VARCHAR(MAX),
CREATE TABLE JOHN(
ID VARCHAR(100),
LINK VARCHAR(MAX),
NAME VARCHAR(MAX),
[DESCRIPTION] VARCHAR(MAX),
[TYPE] VARCHAR(MAX),
CREATED_TIME VARCHAR(MAX),
UPDATED_TIME VARCHAR(MAX),
[COUNT OF LIKES NAME] VARCHAR(MAX),
[COUNT OF COMMENTS MESSAGE] VARCHAR(MAX),
[MESSAGE] VARCHAR(MAX),
SHARES_COUNT VARCHAR(MAX),
EXECUTE (N'BULK INSERT DAVID FROM ''' + 'datapath' + N'david.csv''
WITH (
    CHECK_CONSTRAINTS,
    CODEPAGE=''ACP'',
    DATAFILETYPE = ''char'',
    FIELDTERMINATOR= '','',
    ROWTERMINATOR = ''\n'',
    KEEPIDENTITY,
    TABLOCK
EXECUTE (N'BULK INSERT JOHN FROM ''' + 'datapath' + N'john.csv''
WITH (
    CHECK_CONSTRAINTS,
    CODEPAGE=''ACP'',
    DATAFILETYPE = ''char'',
    FIELDTERMINATOR= '','',
    ROWTERMINATOR = ''\n'',
    KEEPIDENTITY,
    TABLOCK
SELECT * FROM DAVID
SELECT * FROM JOHN
CREATE TABLE NEWDAVID(
POST_ID VARCHAR(100),
[USER_ID] VARCHAR(100),
CREATED_DATE VARCHAR(MAX),
CREATED_YEAR VARCHAR(MAX),
CREATED_MONTH VARCHAR(MAX),
UPDATED_DATE VARCHAR(MAX),
UPDATED_YAER VARCHAR(MAX),
UPDATED_MONTH VARCHAR(MAX),
[MESSAGE] VARCHAR(MAX),
SHARES_COUNT VARCHAR(MAX),
[COUNT OF LIKES NAME] VARCHAR(MAX),
[COUNT OF COMMENTS MESSAGE] VARCHAR(MAX),
NAME VARCHAR(MAX),
[TYPE] VARCHAR(MAX),
LINK VARCHAR(MAX),
[DESCRIPTION] VARCHAR(MAX),
CREATE TABLE NEWJOHN(
POST_ID VARCHAR(100),
[USER_ID] VARCHAR(100),
CREATED_DATE VARCHAR(MAX),
CREATED_YEAR VARCHAR(MAX),
CREATED_MONTH VARCHAR(MAX),
UPDATED_DATE VARCHAR(MAX),
UPDATED_YAER VARCHAR(MAX),
UPDATED_MONTH VARCHAR(MAX),
[MESSAGE] VARCHAR(MAX),
SHARES_COUNT VARCHAR(MAX),
[COUNT OF LIKES NAME] VARCHAR(MAX),
[COUNT OF COMMENTS MESSAGE] VARCHAR(MAX),
NAME VARCHAR(MAX),
[TYPE] VARCHAR(MAX),
LINK VARCHAR(MAX),
[DESCRIPTION] VARCHAR(MAX),
INSERT INTO NEWJOHN
SELECT SUBSTRING(ID, CHARINDEX('_', ID) + 1, LEN(ID) - CHARINDEX('_', ID)) AS POST_ID, 
  SUBSTRING(ID, 1, CHARINDEX('_', ID) -1) AS [USER_ID], 
  SUBSTRING(CREATED_TIME, 1, 10) AS CREATED_DATE,
  SUBSTRING(CREATED_TIME, 1, 4) AS CREATED_YEAR,
  SUBSTRING(CREATED_TIME, 6, 2) AS CREATED_MONTH,
  SUBSTRING(UPDATED_TIME, 1, 10) AS UPDATED_DATE,
  SUBSTRING(UPDATED_TIME, 1, 4) AS UPDATED_YEAR,
  SUBSTRING(UPDATED_TIME, 6, 2) AS UPDATED_MONTH,
  [MESSAGE], SHARES_COUNT, [COUNT OF LIKES NAME], [COUNT OF COMMENTS MESSAGE], NAME, [TYPE], LINK, [DESCRIPTION]
FROM JOHN
INSERT INTO NEWDAVID
SELECT SUBSTRING(ID, CHARINDEX('_', ID) + 1, LEN(ID) - CHARINDEX('_', ID)) AS POST_ID, 
       SUBSTRING(ID, 1, CHARINDEX('_', ID) -1) AS [USER_ID], 
  SUBSTRING(CREATED_TIME, 1, 10) AS CREATED_DATE,
  SUBSTRING(CREATED_TIME, 1, 4) AS CREATED_YEAR,
  SUBSTRING(CREATED_TIME, 6, 2) AS CREATED_MONTH,
  SUBSTRING(UPDATED_TIME, 1, 10) AS UPDATED_DATE,
  SUBSTRING(UPDATED_TIME, 1, 4) AS UPDATED_YEAR,
  SUBSTRING(UPDATED_TIME, 6, 2) AS UPDATED_MONTH,
  [MESSAGE], SHARES_COUNT, [COUNT OF LIKES NAME], [COUNT OF COMMENTS MESSAGE], NAME, [TYPE], LINK, [DESCRIPTION]
FROM DAVID
SELECT * FROM NEWDAVID
SELECT * FROM NEWJOHN
CREATE TABLE POST (
POST_ID VARCHAR(100) NOT NULL,
[USER_ID] VARCHAR(100),
CREATED_DATE VARCHAR(MAX),
CREATED_YEAR VARCHAR(MAX),
CREATED_MONTH VARCHAR(MAX),
UPDATED_DATE VARCHAR(MAX),
UPDATED_YAER VARCHAR(MAX),
UPDATED_MONTH VARCHAR(MAX),
[MESSAGE] VARCHAR(MAX),
SHARES_COUNT VARCHAR(MAX),
[COUNT OF LIKES NAME] VARCHAR(MAX),
[COUNT OF COMMENTS MESSAGE] VARCHAR(MAX),
NAME VARCHAR(MAX),
[TYPE] VARCHAR(MAX),
LINK VARCHAR(MAX),
[DESCRIPTION] VARCHAR(MAX),
INSERT INTO POST
SELECT * FROM NEWDAVID UNION SELECT * FROM NEWJOHN
SELECT * FROM POST 
CREATE TABLE [USER] 
[USER_ID] VARCHAR(100) NOT NULL,
INSERT INTO [USER] VALUES (612831408762037),(1119736203) 
ALTER TABLE [USER] ADD PRIMARY KEY([USER_ID])
ALTER TABLE POST ADD PRIMARY KEY(POST_ID) 
ALTER TABLE POST ADD FOREIGN KEY([USER_ID]) REFERENCES [USER]([USER_ID])

Similar Messages

  • IS there a way to view all the queries executed against a table in sql server 2008 R2

    Hi,
    We would like  to see if a table is getting updated or deleted from external source. Hence we want to know how to see list of queries run against a particular table in sql server 2008 R2.
    Thanks,
    Preetha

    Hi,
    We would like  to see if a table is getting updated or deleted from external source. Hence we want to know how to see list of queries run against a particular table in sql server 2008 R2.
    Thanks,
    Preetha
    Audit, Trigger and custom profiler can be used.
    Balmukund Lakhani
    Please mark solved if I've answered your question, vote for it as helpful to help other users find a solution quicker
    This posting is provided "AS IS" with no warranties, and confers no rights.
    My Blog |
    Team Blog | @Twitter
    | Facebook
    Author: SQL Server 2012 AlwaysOn -
    Paperback, Kindle

  • When i open itunes, it gives me a message "the folder itunes is on a locked disk or you do not have write permissions for this folder" i am the only user and it was working a week ago whats wrong with it? it will not open itunes

    when i open itunes, it gives me a message "the folder itunes is on a locked disk or you do not have write permissions for this folder" i am the only user and it was working a week ago whats wrong with it? it will not open itunes

    Hi lvdmerwe!
    I have two articles here for you that should be able to help you troubleshoot this issue further:
    Trouble adding music to iTunes library or importing audio CD
    http://support.apple.com/kb/ts1387
    iTunes: Missing folder or incorrect permissions may prevent authorization
    http://support.apple.com/kb/ts1277
    Take care, and thanks for visiting the Apple Support Communities.
    -Braden

  • It is very difficult to navigate on facebook via safari. The IPAD does not allow other browsers to download and use it almost prevents the facebook app and the lack of scrolling the page.

    It is very difficult to navigate on facebook via safari. The IPAD does not allow other browsers to download and use it almost prevents the facebook app and the lack of scrolling the page.

    I also have problems with Facebook on my iPad 2. I don't do a lot with Facebook and generally only post on my feed page. Sometimes hitting return on the keyboard enters the comment, sometimes not. Sometimes the comment will show on my iPad but if I revisit that page I find that the comment has disappeared. So I'd say that Facebook and my iPad are not totally compatible with each other.
    I looked into Friendly and was about to purchase this free ap. But before I did I went to the Friendly web page for more info. There I found a page with users comments. One after another users complained about bugs with Friendly. The developers claimed a fix was coming but the user comments complained about the lack of response and support. One of the fixes suggested by the developers was to log out of Friendly then log back in. One user complained that doing this three times in ten minutes was not very helpful. Because of this I decided to avoid Friendly.
    I did find a Facebook developed ap but it was for the iPhone. I presume that iPhone aps will work on the iPad but I'll wait until Facebook releases an iPad compatible ap. If there is an ap developed by Facebook for the iPad that I missed please let me know.

  • HT1349 I can not run the scanner in my main user, but only the second user and the same thing with updating apps! Why is this happening???

    I can not run the scanner in my main user, but only the second user and the same thing with updating apps! Why is this happening???

    Welcome to the Apple Community.
    Enter the details of her second account at system preferences> mail, contacts & calendars.

  • How do I used my iPhone if it is Lock with an Apple ID account of the previous user and i can't longer contact him?

    I bought an Apple Device namely iPhone 4s and this really bother and give me an intimate reason to contact Apple. How do I use the device, if it is Lock with an Apple ID account of the previous user, and everytime I open the phone the screen will show Activate iPhone with the Apple ID link on the Device. The worse thing is that, i couln't contact the seller any longer and the device is seems useless. I can't use it. Please give me some help how to fix this error and vulnerabilities.

    Sorry alvinguibz, but you have encountered an Activation Lock, and unless you can contact the previous owner and have them follow the steps below, you will not be able to use your device:
    Removing Previous Owner from Device
    There is no other way around this.
    Sorry,
    GB

  • I Need to Write the current Date and Time

    I need to write the current date and time to calculate the spend time in each instruction.
    What is the instrucion?
    Thanks.
    MIGUEL ANGEL CARO
    [email protected]

    The current time can be determined with a Date object:
    Date now = new java.util.Date() ;or if you are interested in the seconds since the epoch:
    System.currentTimeMillis() ;If you wanted to print them out:
    System.out.println( new java.util.Date() ) ;
    System.out.println( System.currentTimeMillis() ) ;Kenny

  • Accidentally removed from,sharing and permissions the admin user,and now i do not when i find the home icon at my computer i do not have permmission,and the mac does not works properly,lots of question mark at the dock ,please help

    accidentally removed from,sharing and permissions the admin user,and now i do not when i find the home icon at my computer i do not have permmission,and the mac does not works properly,lots of question mark at the dock ,please help

    I'm going to assume that since you deleted your hard drive and all its files, you had a backup, yes? If the backup has an OS (bootable clone), then you can boot into it by holding down the option key when you start up you iMac and choose the backup drive. Then use Carbon Copy Cloner or Super Duper to copy the files back to your iMac.

  • How can i write the trigger for Global Temporary Table

    Hi Grus,
    How can i write the trigger for Global Temporary Table.
    I was created the GTT with trigger using the below script .
    CREATE GLOBAL TEMPORARY TABLE GLOBAL_TEMP
    EMP_C_NAME VARCHAR2(20 BYTE)
    ON COMMIT PRESERVE ROWS;
    CREATE OR REPLACE TRIGGER TRI_GLOBAL_TEMP
    BEFORE DELETE OR UPDATE OR INSERT
    ON GLOBAL_TEMP
    REFERENCING NEW AS NEW OLD AS OLD
    FOR EACH ROW
    BEGIN
    INSERT INTO EMPNAME VALUES (:OLD.EMP_C_NAME);
    END;
    trigger was create successfully, but the wouldn't insert into to EMPNAME Table..
    Please guide whether am correct or not? if not kindly give a correct syntax with example
    Thanks in Advance,
    Arun M M

    BEGIN
    INSERT INTO EMPNAME VALUES (:OLD.EMP_C_NAME);
    END;
    you are referencing old value in insert stmt.
    BEGIN
    INSERT INTO EMPNAME VALUES (:new.EMP_C_NAME);
    END;then run ur application it works fine...
    CREATE GLOBAL TEMPORARY TABLE GLOBAL_TEMP
    EMP_C_NAME VARCHAR2(20 BYTE)
    ON COMMIT PRESERVE ROWS;
    CREATE OR REPLACE TRIGGER TRI_GLOBAL_TEMP
    BEFORE DELETE OR UPDATE OR INSERT
    ON GLOBAL_TEMP
    REFERENCING NEW AS NEW OLD AS OLD
    FOR EACH ROW
    BEGIN
    dbms_output.put_line(:OLD.EMP_C_NAME||'yahoo');
    INSERT INTO EMPNAME VALUES (:new.EMP_C_NAME);
    dbms_output.put_line(:OLD.EMP_C_NAME);
    END;
    create table EMPNAME as select * from GLOBAL_TEMP where 1=2
    insert into GLOBAL_TEMP values('fgfdgd');
    commit;
    select * from GLOBAL_TEMP;
    select * from EMPNAME;
    output:
    1 rows inserted
    commit succeeded.
    EMP_C_NAME          
    fgfdgd              
    1 rows selected
    EMP_C_NAME          
    fgfdgd              
    1 rows selectedgot it Arun
    Edited by: OraclePLSQL on Dec 28, 2010 6:07 PM

  • Query to find the user is having access to sql server DB

    Hi,
    Please help me in this.
    Query to find the whether the user is having access to sql server DB.
    Cheers,
    sajith

    TUBBY_ORCL?Select 1 from dual where 'ORACLE' = 'SQL SERVER';
    no rows selected
    Elapsed: 00:00:00.01

  • I just bought a used Macbook Pro. How do I make the changes to make it personal. Example the iTunes comes up as the old user and I have to have his password to make changes on the laptop. Can you make any suggestions?

    I just bought a used Macbook Pro. How do I make the changes to make it personal. Example the iTunes comes up as the old user and I have to have his password to make changes on the laptop. Can you make any suggestions?
    Also I cant make a right click on the pad. Is that normal?

    Your first going to have to remove all your personal data off the machine to a external storage drive, do not use TimeMachine when it asks as this will copy the entire drive and is unnecessary at this time (also takes too long).
    You need to drag and drop copy your personal data folders (Music, Pictures, Movies etc) to a external storage drive, once done, unmount and disconnect this drive.
    Most commonly used backup methods
    Next your going to follow the Zero Erase and install method for your OS X version, either 10.6 or 10.7, here
    How to reinstall just OS X or erase/install OS X
    10.7 requires your AppleID and password to install, so make sure to have that ready.
    Once you reboot your into the real setup of OS X, which will require your name etc, so it's now your machine.
    Install your programs, iLife package is only free for the owner of the machine.
    If you have the 10.6 machine specific disks, then it's on there.
    If your using 10.7, then you'll have to purchase it from the App Store.
    Last, return your files from the storage drive, consider setting up a TimeMachine or clone on the external drive.

  • Can any one tell me how to write the properites files and how to acces

    can any one tell me how to write the properites files and how to acces thoose files
    plz let me no
    thanks in advance

    http://www.exampledepot.com/egs/java.util/Props.html

  • SharePoint 2013 - Server Error in '/' Application - This operation can be performed only on a computer that is joined to a server farm by users who have permissions in SQL Server to read from the configuration database

    Hi
    After I ran SharePoint configuration wizard successfully to upgrade to SharePoint 2013 / SP1.
    I can open Central Administration site just fine.
    but now when I open any Site collection,  I got this error.
    Server Error in '/' Application
    This operation can be performed only on a computer that is joined to a server farm by users who have permissions in SQL Server to read from the configuration database. To connect this server to the server farm, use the SharePoint Products Configuration
    Wizard, located on the Start menu in Microsoft SharePoint 2010 Products
    I have restarted all the servers:  SQL server, WFE and APP servers but still cann't get this resolve.
    Services on all servers are running,  IIS - application pools are running.
    Can someone help with where that could be a problem or if there is a solution.
    Thanks in advance for your comments or advices.
    Swanl

    Please verify the followings:
    Make sure that from the SharePoint front end and application servers that you can ping your SQL server.
    Make sure that your Farm account has permission to the configuration database.
    Lastly verify that your database didn't for some reasons go into recovery mode.
    once everything is fine and you are still having issues, restart the SQL host service on the SQL server.
    Once the service is restarted you will need to reboot Central Admin and then your front end servers.
    In addition, as you built your farm inside the firewall, please disable the firwall, or create rules for SQL Server service in the firwall on SQL server.
    More information about creating rules in firewall, please refer to the following posts: http://social.technet.microsoft.com/Forums/en-US/c5d4d0d0-9a3b-4431-8150-17ccfbc6fb82/can-not-create-data-source-to-an-sql-server http://www.mssqltips.com/sqlservertip/1929/configure-windows-firewall-to-work-with-sql-server/
    Here is a similar post for you to take a look at: http://social.technet.microsoft.com/Forums/en-US/ea54e26c-1728-48d4-b2c5-2a3376a1082c/this-operation-can-be-performed-only-on-a-computer-that-is-joined-to-a-server-farm-by-users-who-have?forum=sharepointgeneral 
    Please 'propose as answer' if it helped you, also 'vote helpful' if you like this reply.

  • I am the the only user and the administrator for my laptop and I have forgotten my password so I can't make any changes or download any programs....

    I am the the only user and the administrator for my laptop and I have forgotten my password so I can't make any changes or download any programs....

    Reset Password using Recovery HD
    Boot into Recovery Partition.
    Start the computer,then press and hold down command and R keys to start into recovery partition.
    When you see the Apple logo, release the keys.
    Wait until you see OS X Utilities window shows up.
    Move the mouse to the menubar at the top and click "Utilities", then select "Terminal"
    from the drop down.
    Terminal window will appear.
    Type in   resetpassword   and press enter key on the keyboard.
    Do not close the Terminal window
    Reset Password Utility window will open with Macintosh HD selected.
    Select the user account from the popup menu box.
    Enter a new password.
    Reenter the new password for the user.
    Enter a hint.
    Click the "Save" button.
    Click  in the menubar and select Restart.

  • How EM invokes the concurrent users and list of parameters scripts in EM ?

    Hi,
    How to check if EM is invoking the concurrent users and list of parameters scripts for a db instance target or not ?
    And how EM invokes these in EM ?
    Thanks in Advance.

    Not sure what you mean with this question, could you be a bit more specific?
    Regards
    Rob
    http://oemgc.wordpress.com

Maybe you are looking for

  • My imac spits out the Cd-r and I can't burn a disc

    My iMac spits out the CD-R and I can't burn a disc

  • Unreadable text in Edit mode

    When I open my web pages in Contribute, I can see the text but when I press Edit, the text area goes grey and I can't see the text. Help, please!

  • No sound in photobooth or imovie!?

    I just tried recording a video using photobooth and when i played it back the sound didn't work. It has definitely worked before and i tried it again and it didn't work so it's not random there must be something wrong with it. I looked online to see

  • In adobe form, how to disappear the part as the picture shows?

    Could someone give me a hint please? Thanks in advance.

  • Step 1: Setup

    What is the most basic, affordable setup an editor can effectively work with? My computer specs are listed below, but I only use 1 23" Apple Cinema Display and a cheap 32" LCD TV (reference monitor, kind of). What would you recommend to improve my "s