2014-10-19 35 views
-2

我提供的問題是:在SQL Server中編程數據庫

編寫DDL來構建SQL Server中的Facebook用戶和Post表。您需要使用圖1中提供的用戶信息填充用戶表,並且設計可能需要其他屬性。使用Excel文件中的ID標識其他Facebook用戶。例如ID 612831408762037是David Cunliffe。將Excel表導入SQL服務器,然後編寫有效的SQL將兩個表合併到Post表中。

到目前爲止,我編寫的代碼是:

IF EXISTS(
    SELECT * 
    FROM sys.tables 
    WHERE name = N'FacebookUser' 
) 
DROP TABLE FacebookUser; 

IF EXISTS(
    SELECT * 
    FROM sys.tables 
    WHERE name = N'Post' 
) 
DROP TABLE Post; 

CREATE TABLE FacebookUser 
(UserID varchar(15) primary key not null, 
    UserName varchar(30) not null, 
    UserDescript varchar(500), 
    JoinDate date not null, 
    HomeTown varchar(30), 
    Affiliation varchar(30), 
    Country varchar(30), 
    CurrentOffice varchar(100), 
    Gender varchar(6) not null, 
    Email varchar(30), 
    OtherAccounts varchar(100), 
    Website varchar(500), 
); 

CREATE TABLE Post 
(id char(28) not null, 
    message varchar(8000) not null, 
    type varchar(15) not null, 
    created_time datetime not null, 
    updated_time datetime not null, 
    shares.count int not null, 
    count of likes.name int not null, 
    count of comments.message int not null, 
    Link varchar(50) not null, 
    name varchar(50) not null, 
    Description varchar(200) not null, 
); 

INSERT INTO FacebookUser 
VALUES('612831408762037', 'Some Name', 'Some very long text to insert in my row just for test cases', 
    '02/18/2009', 'New Lynn/Auckland', 'New Zealand Labour Party', 'New Zealand', 'Office: Member of Parliament for New Lynn Party: New Zealand Labour Party', 'Male', 
    '[email protected]', 'Some Name (Other Service)', 'www.example.com'); 

INSERT INTO FacebookUser 
VALUES('1119736203', 'Another Name', 'Some other example text, with some extend ', '02/20/2008', NULL, 
    NULL, 'New Zealand', 'Office: Prime Minister Party: NZ National Party', 'Male', '[email protected]', NULL, 
    'http://example.com'); 

我已經導入的數據,但我不確定如何將數據合併到第二個表,我得到的這幾行代碼的錯誤:

shares.count int not null, 
    Link varchar(50) not null, 
    name varchar(50) not null, 
    Description varchar(200) not null, 

我完全從這裏失去。有人能幫助嗎?

回答

0

你將不得不使用方括號這是關鍵字或包含空格或無效字符

 [shares.count] int not null, 
     [count of likes.name] int not null, 
     [count of comments.message] int not null,  

此外,你將不得不確保該領域是大到足以讓你想要的值字段名存儲,其他方式,你會得到像String or binary data would be truncated.

相關問題