![]() |
SQL Help
I have used SQL before in some very basic and limited fashion. I know how to write select and insert statements but that's about it.
We currently use flat .DBF file for our customer database at work. I am going to propose a solution that uses an SQL server but I have some questions for the SQL GURU's around here. First off, can sql tables have associated indexes and if so, how do you access the information via the index? For example if I enter a phone number I want to be able to jump to that phone number if it exists. If it does not exist, I need to go to the closes match and be able to go to the previous and next records. Next, I need to know how to set permissions on tables. I have one table that everyone needs read access to, but only 3 people need write access to. I will have both internal and external sources looking at some of these tables so will need to set the security appropriately. I will be doing my developnet in Delphi, not that it should make a difference though. Thanks for your advice, I will probably have more questions later. Hrd edited to add another point |
Quote:
Quote:
Quote:
The second part is somewhat more complicated because I am not sure what you mean by 'closest match'. Is 'closest' the nearest one if the phone number is treated as a single integer, or one with the least number of substitutions to arrive to the one you want? Or something else entirely? Quote:
Of course depending on your actual application, you may want to always connect as the same user and handle permissions in your app (for performance reasons, this is usually the way it's done in web applications). Quote:
Quote:
|
What franzelneekburm said. Only you can also use MySQL, which is free and does it's job well. It's not as full featured as other database servers, but you can find TONS more info on MySQL vs PosgtreSQL (my opinion, not fact). Even better would be to use MSSQL or Oracle should you have access to either of them.
|
I'll be using MySQL because that's what I'm familiar with and it's free. :)
Thanks for your answers and suggestions. |
if you want to use the indexing thing as you describe it, here's one way of doing it. (I'm used to using MSSQL and Oracle, so my syntax might be slightly different than for MySQL)
Code:
create table phones will return 2 you can then offer the details associated with alphasort number 2, or add 1 for the next, or minus 1 for the previous. You will have to reindex the list every time someone enters a new number though. This could be done using a cursor (if they are supported by MySQL, or programmatically by loading an ordered select and then doing some iterated updates) It would be handy to do this re-indexing via SQL, but I'm not sure I know how to do that without resorting to stored procedures etc - if anyone does, it would be a VERY useful thing to know - please post! |
As for the read/write functionality, you could use a view on the table to provide read only access (but check because some RDBMSs allow updates on views)
|
The phone number was an example, and to answer franzel's question, yes, the phone number would be treated as an integer so if I had the following numbers:
123-1234 123-1235 123-1237 123-1238 and I searched for 123-1236 it would return 123-1237 other things would be names. Searching on will would return williams, willson etc. |
Quote:
The way I usually solve similar problems: Assuming your phone numbers use the same formatting and will sort in the way you want as strings (ie if some are '(123) 456 5555' and others are '123-456-6666' the sorting might not be what you want) Code:
CREATE TABLE employees ( Code:
SELECT employee_id, phone FROM employees WHERE phone > '444-444-4444' ORDER BY phone LIMIT 5; you'll probably want to normalize the numbers just in case though, one way to do it is to create a function that strips everything but numbers from the string (and returns it as an integer) and then index on that, so: Code:
CREATE INDEX idx_employees_phone ON employees (strip_alpha(phone)); |
Quote:
I use it for some projects, and I like it, but sometimes the things it does to my data just really scare me (this is part of their 'Best Effort' philosophy, I guess it's a subjective call). As far as documentation goes, I agree that MySQL's is excellent while Postgres' is just very good; but for what a beginner needs both will do just fine. Quote:
I've found that for small to medium projects the extra administrative and development overhead that comes with Oracle is just not worth it. I have a couple of die-hard Oracle fans that came into our mostly Postgres environment, over two years there hasn't been a single "Well, in Oracle I could..." for which I couldn't show an equivalent (or better) solution in Postgres. Rule of thumb: if your project will need live replication, then think about Oracle; if not, you are likely to just be wasting time and money. I have no experience with MSSQL, so I can't comment there. |
what about stroring the phone numbers as 3 seperate integer values (area code, prefix, suffix)? So the number (410)321-1234 would be stored with an area code of 410, a prefix of 321, and a suffix of 1234. You could then sort by each of those columns...
Maybe I'm missing an obvious downfall, but it seems like it would make the sorting easier. |
All times are GMT -8. The time now is 12:00 PM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
Search Engine Optimization by vBSEO 3.6.0 PL2
© 2002-2012 Tilted Forum Project