数据库结构问题。解决马上给分

我目前的库的列有以下几个。
id int (自动增加)
artist (歌手字段) 有重复 关键查找字段
titlie (歌曲名字) 也有重复 关键查找字段
url (所在urlconnect (成功率))
class (文件类型) 有重复。搜索时候需要判断是否包含这个类型,比如只搜索mp3
protocol(协议类型)有重复。搜索时候需要判断是否包含这个类型,比如只搜索ftp
size (尺寸)
defer (速度)

date (日期)
special (专辑) 有重复。有可能搜索某个专辑的歌曲
zone (地区) 有重复。可能需要指定地区查找。比如只要大陆的。
language (语言) 有重复。可能需要制定查找。比如只要国语的。
issuer (发行)
intro (介绍)

下面给出几个例子条目作为参考,间隔副用,号。只放出id,歌手,歌曲和专辑。应为
其他的不是很重要
1,张雨声,两个传说,http://www.xxx.com/lll.mp3,专辑1
2,张雨声,两个传说,http://www.xxx.com/222.mp3,专辑1
3,张雨声,两个传说,http://www.xxx.com/333.mp3,专辑1
4,张雨声,没有传说,http://www.xxx.com/444.mp3,专辑1
5,张雨声,没有传说,http://www.xxx.com/555.mp3,专辑1
6,张雨声,没有传说,http://www.xxx.com/666.mp3,专辑1
7,张雨声,没有传说,http://www.xxx.com/777.mp3,专辑1
8,刘德华,本小孩,http://www.xxx.com/aaa.mp3.专辑2
9,刘德华,本小孩,http://www.xxx.com/bbb.mp3.专辑2
10,刘德华,本小孩,http://www.xxx.com/ccc.mp3.专辑2
11,刘德华,本小孩,http://www.xxx.com/ddd.mp3.专辑2
12,刘德华,马桶,http://www.xxx.com/eee.mp3.专辑2
13,刘德华,马桶,http://www.xxx.com/fff.mp3.专辑2
14,刘德华,马桶,http://www.xxx.com/ggg.mp3.专辑2
15,刘德华,马桶,http://www.xxx.com/hhh.mp3.专辑2

用户每次查询需要返回的是歌手或者歌曲或者专辑列的和查询关键字相关的所有条目。
当然也可以指定查询的列。
显然直接对着个库进行搜索效率非常低下。

另外。我现在用的是mysql.如果有可能可否请帮忙解决mssql和mysql两个版本的库?

我的构想是这样的这样的。在建立一个专门用来查找歌手的表和一个查找歌曲的和查找专辑的表。
比如。如果是查询歌手关键字的。
那么建立的表如下(根据上表建立)

1 张雨声 1,2,3,4,5,6,7
2 刘德华 8,9,10,11,12,13,14,15

/这样如果搜索的关键字是“张雨声”那么直接取后面的1,2,3,4,5,6,7到上面一张表去区回数据。。不知道这样可行否?

反过来也是一样建立歌曲表
1 两个传说 1,2,3
2 没有传说 4,5,6,7
3 本小孩 8,9,10,11
4 马桶 12,13,14,15
/如果搜索歌曲就直接查询着个表。

如果同时搜索。那么可以在两个表中同时搜索。或者在建立一个表。

我是数据库初学者。不知道这样是否可行?
或者提供跟好地方案

另外。如何把mysql数据库导入倒mssql中呢?

---------------------------------------------------------------

do not use "," separated column values, do something like the following instead:

1. singers
singer_id
singer_name
(other info....)

examples:
1 张雨声
2 刘德华

2. albums (assume an album only belongs to one singer, otherwise, split the table into two)
album_id
album_name
singer_id

examples:
1 专辑1 1
2 专辑2 2

3. songs
song_id
song_name
album_id
singer_id (in case there are songs which do not belong to any album)

examples:
1 两个传说 1 1
2 没有传说 1 1
3 本小孩 2 2
4 马桶 2 2

4. songs_on_the_net
song_id
url

examples:
1 http://www.xxx.com/lll.mp3
1 http://www.xxx.com/222.mp3
1 http://www.xxx.com/333.mp3
2 http://www.xxx.com/444.mp3
2 http://www.xxx.com/555.mp3
2 http://www.xxx.com/666.mp3
2 http://www.xxx.com/777.mp3
3 http://www.xxx.com/aaa.mp3
3 http://www.xxx.com/bbb.mp3
3 http://www.xxx.com/ccc.mp3
3 http://www.xxx.com/ddd.mp3
4 http://www.xxx.com/eee.mp3
4 http://www.xxx.com/fff.mp3
4 http://www.xxx.com/ggg.mp3
4 http://www.xxx.com/hhh.mp3

the above table structure is good for updates, but if your data is mainly readonly and you need high search speed, denormalize the tables

>>>>如何把mysql数据库导入倒mssql中呢?
Migrating MySQL to Microsoft SQL Server 2000
http://www.microsoft.com/technet/treeview/default.asp?url=/technet/prodtechnol/iis/deploy/depovg/MySQL.asp

SQL Server FAQ: How can I migrate a MySQL database to SQL Server 2000
http://www.sqlservercentral.com/faq/viewfaqanswer.asp?categoryid=2&faqid=70
---------------------------------------------------------------

create table #temp (artist int, id varchar(1000))
declare @i int
declare @max int
set @i = 1
select @max = max(id) from b
while @i <= @max
begin
if exists (select * from #temp where artist = (select artist from b where id = @i) )
update #temp set id = A.id + ',' + cast(B.id as char) from #temp as A, b as B where A.artist = B.artist and B.id = @i
else
insert #temp select artist, cast(id as char) from b where b.id = @i
set @i = @i + 1
end
select * from #temp order by artist
drop table #temp

Published At
Categories with 数据库类
Tagged with
comments powered by Disqus