2014-10-19 38 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.

相关问题