SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseSQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old January 7th, 2004, 08:58 AM
patekw patekw is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 2 patekw User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy SQL for file structure

I am trying to develop a database simulating a file structure on the harddisk. Some files and folders stored in the db other words.
The problem is that i cannot figure out how to build the database and how to write the SQL.
I started to build a table with idīs for every folder and subfolders, giving the subfolder the parentID of the mainfolder. Can i do like that? In that case, how to write the query sorting in in the right way? Some kind of recursive query maybe?
I am grateful for help and DB/SP examples.

Best regards
Patekw

Reply With Quote
  #2  
Old January 7th, 2004, 09:12 AM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
Click here for more information.
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,879 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 18 h
Reputation Power: 500
You could do this many different ways. Probably the best way would be to have 2 tables (Folders and Files) and then just relate the together.

Here is an easy 1 table way to do it.
File Table (For SQL Server)

FId (uniqueIdentifier)
FolderName (varchar(50))
FileName (varchar(50))
ParentFolderId (uniqueIdentifier)
IsFile (bit) <---- determines if its a file (1) or a folder (0)

example structure
Code:
FId - 000-0-0001
FolderName - MyFolder
FileName - (this is blank because it is a folder)
ParentFolderId - (this is blank, because it is the root (main) folder)
IsFile - 0 (no)

FId - 000-0-0002
FolderName - FolderA
FileName - (Blank)
ParentFolderId - 000-0-0001 (its parent is above)
IsFile - 0 (no)

FId - 000-0-0003 
FolderName - (blank)
FileName - file.txt (this is a file)
ParentFolderId - 000-0-0002 (This file is in FolderA)
IsFile = 1 (yes)

etc...

Reply With Quote
  #3  
Old January 7th, 2004, 09:29 AM
patekw patekw is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 2 patekw User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks! That may work, but how to query the DB for the right output for folders and files?

Reply With Quote
  #4  
Old December 23rd, 2004, 05:32 AM
pitipat_pk pitipat_pk is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 1 pitipat_pk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Recursive query

Quote:
Originally Posted by patekw
Thanks! That may work, but how to query the DB for the right output for folders and files?

I think that I am replying to your question pretty late, but I just saw this today. Anayway... here are 2 ways of writing the recursive query that you want.. I am not sure about the syntax of the 2nd answer. You might verify it before using...

1.
select folderName, fileName, isFile
from File_table
startwith ParentFolderID isnull
connectbyprior FId = ParentFolderId;

2.
with
search as(
select FId, folderName, FileName, isFile from File_table root, ParentFolderId
unionall
(select child.FId, child.folderName, child.FileName, child.isFile, child.ParentFolderId
from search parent, File_table child
where child.ParentFolderId = parent.FId))
select*from search;

Reply With Quote
  #5  
Old December 24th, 2004, 02:48 AM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
Click here for more information.
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,879 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 18 h
Reputation Power: 500
Quote:
Originally Posted by pitipat_pk
I think that I am replying to your question pretty late

I would think you are a little late answering this question...considering he asked it almost a year ago.

In the future, please don't resurrect dead threads.

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseSQL Development > SQL for file structure


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT