|
Hi guys. I have a really stupid question. Sample table (this is MS SQL server 2005): code:
code:
|
# ? Aug 23, 2010 04:03 |
|
|
# ? May 14, 2024 08:58 |
|
Thel posted:Hi guys. I have a really stupid question. Fortunately, since you are using 2005, I can answer with my favorite thing ever, analytical/window functions: code:
Jethro fucked around with this message at 19:58 on Aug 23, 2010 |
# ? Aug 23, 2010 19:56 |
|
I'm trying to write a deployment script, and would like to be able to call sqlcmd to execute every query in a specified directory. I think the problem is that it's looking for a file instead of a directorycode:
code:
PuTTY riot fucked around with this message at 05:52 on Oct 20, 2010 |
# ? Aug 24, 2010 17:53 |
|
Hey guys, is there a defacto book for MySQL for learning the ins and outs from both a developers perspective and a dba perspective? I'm just starting at a new job and realized my SQL skills were pretty weak, especially with MySQL. Any advice is appreciated, I'm looking forward to spending some money on amazon
|
# ? Aug 24, 2010 20:22 |
|
For the last five years, I've been doing my standard joins like so:code:
code:
|
# ? Aug 24, 2010 20:39 |
|
Golbez posted:But based on my cursory research, this 'implied' join is functionally an inner join, rather than a left join. Is this correct? Yep.
|
# ? Aug 24, 2010 20:41 |
|
Golbez posted:For the last five years, I've been doing my standard joins like so:
|
# ? Aug 24, 2010 20:42 |
|
Golbez posted:It's been suggested I simply do... It sounds like you work with nitpickers. I prefer writing out the joins just as you do as it's more legible, easier to understand, and easier to change.
|
# ? Aug 24, 2010 21:22 |
|
Mackerel, the Thief posted:It sounds like you work with nitpickers. I prefer writing out the joins just as you do as it's more legible, easier to understand, and easier to change. I agree that explicit join syntax is the way to go. Far more systematic (since afaik you need to use it in order to express anything other than an inner join), and easier to understand.
|
# ? Aug 24, 2010 21:36 |
|
Mackerel, the Thief posted:It sounds like you work with nitpickers. I prefer writing out the joins just as you do as it's more legible, easier to understand, and easier to change. It's literally the first time I've ever worked with other coders, and I'm the new guy, so I'm very much inclined to do what they want to fit with their style. My hope is, in a few months, I can start hopefully influencing them instead of the other way around. I'd love to introduce this joint to objects and mysqli/PDO.
|
# ? Aug 24, 2010 21:57 |
|
Golbez posted:... I'd love to introduce this joint to objects ... They... don't... use objects?! Like, at all? Everything procedural?
|
# ? Aug 24, 2010 22:10 |
|
Mackerel, the Thief posted:They... don't... use objects?! Like, at all? Everything procedural?
|
# ? Aug 24, 2010 22:30 |
|
Help me write a (query. I have two tables, one a listing of vote cards, the other a list of votes. Each vote card can have one or more votes for a player. So for each entry in the votecard table, there are 1 or more entries in the votes table giving a certain amount of votes to a particular player. I want a query that will return a list of votecards and the total number of votes given on that card. Basic table data shown below: code:
code:
|
# ? Aug 25, 2010 06:40 |
|
Figured it out. was going about it completely wrong. Just needed a simply query with a group by statement -_-
|
# ? Aug 25, 2010 07:16 |
|
boak posted:Help me write a (query. I have two tables, one a listing of vote cards, the other a list of votes. This looks like a simple problem. code:
Sprawl fucked around with this message at 07:43 on Aug 25, 2010 |
# ? Aug 25, 2010 07:20 |
|
In a situation where transactional integrity isn't required (I'm not updating bank records here), is there any reason at all to be fancy and go with a multiple-table delete statement in MySQL over the much more understandable and sane method of using two individual delete statements?code:
code:
|
# ? Aug 25, 2010 23:04 |
|
Golbez posted:In a situation where transactional integrity isn't required (I'm not updating bank records here), is there any reason at all to be fancy and go with a multiple-table delete statement in MySQL over the much more understandable and sane method of using two individual delete statements? I would go for the single statement because to me it seems if anything simpler. (In most situations like this I would expect a single-table delete statement would suffice, as cascading deletes would take care of the rest.)
|
# ? Aug 25, 2010 23:20 |
|
Hammerite posted:I would go for the single statement because to me it seems if anything simpler. (In most situations like this I would expect a single-table delete statement would suffice, as cascading deletes would take care of the rest.) The first one seems simpler than the second?
|
# ? Aug 25, 2010 23:35 |
|
Golbez posted:The first one seems simpler than the second? Why wouldn't you just add a FOREIGN KEY with an on delete to remove the entires from the other table?
|
# ? Aug 25, 2010 23:45 |
|
Golbez posted:The first one seems simpler than the second? Now that I look at it again: I had assumed that "list_contacts" was a child table of "lists", with "list_id" in "list_contacts" being a foreign key to "lists". Assuming that this is the case, I would (if it were my database design) have set up the foreign key specifying ON DELETE CASCADE. Therefore both of the queries you exhibited would be over-complicated because the following would do: code:
code:
If there might be rows from list_contacts in which list_id = 15 but no rows from lists in which the same is true, then the above query would not delete the same sets of rows as the pair of single-table delete queries you presented. (But then I might question the table design, or at least the naming of columns.) But to give a shorter answer, the first one seems cleaner to me. It may not be as simple as the pair of queries, but nevertheless I would describe it as "simple" because I do not think it unduly complicated.
|
# ? Aug 25, 2010 23:53 |
|
Sprawl posted:Why wouldn't you just add a FOREIGN KEY with an on delete to remove the entires from the other table? I was going to say, "Never used it before, but I'll read up on it and find out if we can". Then I discovered it's only supported for InnoDB, and we use MyISAM exclusively. Golbez fucked around with this message at 14:29 on Aug 26, 2010 |
# ? Aug 26, 2010 14:25 |
|
Golbez posted:I was going to say, "Never used it before, but I'll read up on it and find out if we can". Is there a reason? We were using MyISAM and I switched the tables I use to InnoDB so I could use foreign keys. No problems so far except apparently InnoDB saves some kind of log file that can take up a lot of room if you leave it set at the defaults.
|
# ? Aug 26, 2010 14:42 |
|
Doctor rear end in a top hat posted:Is there a reason? We were using MyISAM and I switched the tables I use to InnoDB so I could use foreign keys. No problems so far except apparently InnoDB saves some kind of log file that can take up a lot of room if you leave it set at the defaults. 'For the types of data and queries we run, they perform the best'.
|
# ? Aug 26, 2010 14:54 |
|
Golbez posted:'For the types of data and queries we run, they perform the best'. Okay your shittin me that's a bunch of lies.
|
# ? Aug 26, 2010 18:31 |
|
Golbez posted:'For the types of data and queries we run, they perform the best'. If you make heavy use of fulltext indices this might be the case but otherwise whoever said this is probably basing it on data from quite old versions of MySQL.
|
# ? Aug 26, 2010 19:10 |
|
Suppose I have a physical test system where a user places a sample into the rig and runs an experiment that returns a set of a hundred or so (X,Y) data points. I want to store this data in MSSQL, and to my SQL-newbie way of thinking the tables should look something like ExperimentTable experimentID partID operator testDate etc. DataTable experimentID xData yData where the experimentID field in DataTable is keyed to the experimentID field in ExperimentTable. This layout is simple and would work OK on day one, but after a few years of operation the DataTable set is going to get goddamn huge which might result in slow data retrieval, and if I use a 32-bit integer for experimentID and reals for the X,Y data fields a full 33% of the DataTable will be taken up with largely redundant experimentID key info. Is there a better way to store this kind of information? I guess what I'd really like is some sort of Table-of-Tables where I could store the X,Y datasets in a block and reference them all as one unit. Does that kind of DB structure even exist, and if so what is it called so that I can Google for more info? Am I overthinking this and falling into the old premature optimization trap?
|
# ? Aug 27, 2010 15:32 |
|
We collect much greater amounts of data than that, but we archive it into separate tables once it's a year old. Is that something you can do, or will you need to compare old data to new data regularly? I guess you could make a view that's a union of all the tables. Are there always going to be the same amount of X, Y data sets? If so, you could make a column for each coordinate and name them appropriately.
|
# ? Aug 27, 2010 15:39 |
|
Doctor rear end in a top hat posted:We collect much greater amounts of data than that, but we archive it into separate tables once it's a year old. Is that something you can do, or will you need to compare old data to new data regularly? I guess you could make a view that's a union of all the tables. Thanks for the reply. I thought about doing this and it might end up being the best overall solution even if it does complicate the queries a bit. The users don't see the query however, so it's just a matter of me taking an extra hour or so to write a more general algorithm. If nobody suggests any other solutions it's most likely what I'll end up going with. I just figured it was worth asking to see if there was a better way before I begin. Doctor rear end in a top hat posted:Are there always going to be the same amount of X, Y data sets? If so, you could make a column for each coordinate and name them appropriately. The tests can return a variable number of points and the max number of points that could possible be generated is huge, so I think it's got to stay in column format.
|
# ? Aug 27, 2010 16:00 |
|
Specifically we store about 20,000 records daily in one of our tables with an average row size of 550 bytes, which is only ~10 MB per day, so not as much as I thought. I'm guessing your rows should be around 12 or 16 bytes each?
|
# ? Aug 27, 2010 16:18 |
|
Yeah, each record would be about 12 bytes so for an average of 100 points per test it would be a little more than 1kb each run. If they did 100 tests per day for a year it'd generate about 40Mb of data. Run the system for 10 years at that rate and its still less than half a gigabyte. Looking at it that way I guess I am overthinking things and should just lump everything into one big table. In fact I shouldn't even do the archive-by-year thing, half a gig is nothing to a modern machine. Thanks for helping put that into perspective.
|
# ? Aug 27, 2010 16:44 |
|
gently caress I hate computers. If I have a field in a database with codes and a table linking codes to captions, how hard is it to write a function to take a list of codes and spit out the captions? (MS SQL 2005)code:
NULL ,A1, ,A3,A4, ,A1,A4,A5, are all valid entries for that column (I'm doing this in SQL to make a view for a report I'm writing in Crystal - of the two, I'd much rather deal with SQL.)
|
# ? Aug 29, 2010 05:06 |
|
That's really easy to do in crystal with a Formula Field. But its really hard to recommend what to do on the sql side without seeing what is doing the "magic".
|
# ? Aug 29, 2010 07:37 |
|
Sprawl posted:That's really easy to do in crystal with a Formula Field. It would be easy to do in Crystal, yes, but I'm trying very hard to avoid doing anything aside from "put the text box here and make it look pretty" in Crystal since we're going to be shifting to SSRS (soon™). Also, wouldn't it be a pain in the rear end to cope with the fact that 'stuff' can have multiple selections? As far as what 'magic' is, I was thinking a scalar function - one string in, one string out. I'm just wondering how hard it would be to write.
|
# ? Aug 29, 2010 09:52 |
|
Thel posted:gently caress I hate computers. If I have a field in a database with codes and a table linking codes to captions, how hard is it to write a function to take a list of codes and spit out the captions? (MS SQL 2005) http://www.simple-talk.com/sql/t-sql-programming/concatenating-row-values-in-transact-sql/ There's several ways there, from the UDF approach to using XML functions to do it for you. On 2005 I'd probably go with the XML method, as UDFs can be a little 'black box' to the query optimiser, meaning it won't be able to correctly guess the output, and might generate a non-optimal query plan. Edit: Sorry - You mean that the codes are stored as "a1,a2,a3" in a single column's cell? Jesus wept. In that case you can split them into a table variable with a string splitting function - Take a look at http://www.sommarskog.se/arrays-in-sql-2005.html for a lot of ways to do this, pick depending on circumstances and then use the table variable as the base for the XML method as per above Molotov Cock Tale fucked around with this message at 13:51 on Aug 29, 2010 |
# ? Aug 29, 2010 13:48 |
|
PDP-1 posted:Thanks for helping put that into perspective. I've got a simple many-to-many table linking two integer ids A and B with a measly 16 million rows. Mysql tells me the table data is just 137 mb (which is great!) with "Row length ø 9". Now there is also a primary index featuring both columns (A,B) for distinctiveness and an index for each column (A might be redundant since it's a prefix of the primary). These indices weigh in with an additional 617 mb and blow the Row size to 49B - a factor of 5. So, in theory, is there any way to index this more compactly without loosing too much performance? At this point i kinda doubt it (except maybe for dropping that redundant prefix index) but maybe there's just some nifty trick i'm missing (since int-int many-to-many tables seem like a really really common thing) everybody already knows about.
|
# ? Aug 29, 2010 16:26 |
|
RoadCrewWorker posted:So, in theory, is there any way to index this more compactly without loosing too much performance? At this point i kinda doubt it (except maybe for dropping that redundant prefix index) but maybe there's just some nifty trick i'm missing (since int-int many-to-many tables seem like a really really common thing) everybody already knows about. The index on A is redundant, yes. Assuming you will have a need to join on B, I don't think you can do better than having two indexes, one on (A, B) and the other on B.
|
# ? Aug 29, 2010 17:11 |
|
Thel posted:It would be easy to do in Crystal, yes, but I'm trying very hard to avoid doing anything aside from "put the text box here and make it look pretty" in Crystal since we're going to be shifting to SSRS (soon™). Also, wouldn't it be a pain in the rear end to cope with the fact that 'stuff' can have multiple selections? Oh so you haven't done any of the grouping part? I dont think i quite get the grasp of all your tables so its a little hard to guess at the tables and layout but this should be the jist of it. code:
code:
Sprawl fucked around with this message at 18:56 on Aug 29, 2010 |
# ? Aug 29, 2010 18:50 |
|
I've got a MySQL 5 server, and I'm wondering if it's possible to restrict a database (not just tables within a database) to a size limit, say 500MB or so. All the information I've been able to dig up through Google and the MySQL website is about hard limits (such as the MyISAM + Linux/ext4 2GB limit) rather than imposing soft limits like this. I'm wanting to do this as a precaution against spam filling up in databases. One DB I recently purged had over 800MB of phpBB spam posts (and another 400MB of search indexer rows). Thanks
|
# ? Aug 30, 2010 00:28 |
|
Hoborg posted:I've got a MySQL 5 server, and I'm wondering if it's possible to restrict a database (not just tables within a database) to a size limit, say 500MB or so. There's no option for this. Your best workaround is to write a cron to look for stuff to be deleted.
|
# ? Aug 30, 2010 04:19 |
|
|
# ? May 14, 2024 08:58 |
|
Sorry if I wasn't clear before - I'm working with a proprietary CRM system, and this is their implementation of multi-selects - and yes it is multiple Capt_Codes in a single element (stored as nvarchar(255)). Clearly tables are a precious commodity but client-side computer time is cheap ... or the developers of this system are incompetent assclowns. I've managed to write a table-valued function to split said string into it's component codes (from which I just need to join to the captions table, then mash everything back into a string). However, there is a complication, namely that the database has to run in SQL Server 2000 compatibility mode, and trying to feed a TVF a field name results in some bollocks about it not being a recognised hint. In short, gently caress my life and gently caress SageCRM.
|
# ? Aug 30, 2010 04:46 |