4
votes
2answers
5k views

SELECT TOP in MySQL

How can I do this in MySQL? SELECT TOP 50 PERCENT * FROM table What's the simplest way to do it without running to separate queries (if possible)?
1
vote
1answer
44 views

What is this type of query called, and how can I formulate it?

I have following tables: events(event_id, name, description) groups(group_id, event_id, title, description) event_group(event_id, group_id) users(user_id, name, email) ...
7
votes
1answer
2k views

PostgreSQL data type text vs varchar without length

In PostgreSQL you can create a column with data type character varying (without length precision) or text like this: ALTER TABLE test ADD COLUMN c1 varchar; ALTER TABLE test ADD COLUMN c2 text; Is ...
2
votes
2answers
708 views

What could trigger that a login created from a certificate is not visible in metadata

I am trying to create a login and grant it rights to run and unsafe assembly but the check on server_principals does not return the login when it already exists. The script works perfectly fine on my ...
5
votes
3answers
2k views

SQL server indexing foreign keys, covering indexes included columns

I have pulled a list of FK's that do not have indexes on them. If a FK does not have a dedicated index on them but are part of wider indexes used for covering queries, Should they have a dedicated ...
2
votes
1answer
167 views

Optimising a query using hint locks

I have a stored procedure that is being called very frequently. For some database servers it is as often as 20 times per second. Unfortunately because different clients call this procedure, I can't ...
2
votes
2answers
99 views

which option is better for not slow down the performance of queries?

I am developing a system that records customer payments, when a customer makes a payment, the system must update the account and show the payment made and all previous payments, is here when the ...
8
votes
2answers
6k views

Running SQL Query on all databases

I have one hosting account using cPanel and phpmyadmin. I have 50 databases under this account, all WordPress. I need this query modified so that it runs through all databases to update the ...
4
votes
2answers
5k views

Directory lookup failed when adding sample database to SQL Server 2012

I am trying to add the AdventureWorks sample database to SQL Server 2012, but I get an error message: Msg 5133, Level 16, State 1, Line 1 Directory lookup for the file "C:\Users\A\Documents\SQL ...
4
votes
1answer
145 views

How can I improve this design?

I'm creating an event planning PHP/MySQL web application as a learning project. The whole app revolves around the idea of the event and its various components (participants, groups, lists, etc.) I ...
-3
votes
1answer
2k views

How to Create a Trigger in SQL Server to Update Cascade When @@RowCount > 1?

I Have 2 Table Table1 | column name | type | |-------------+-------------| | ID1 | Int | | Name | NVARCHAR(50)| Table2 | column name | type | ...
4
votes
3answers
2k views

SQL Server 2005/2008 system timezone

I work on a ship that has multiple SQL Servers, both 2005/2008 versions. As the ship moves from area to area so does our timezone. Sometimes we can jump ahead one hour and then back again. My ...
5
votes
1answer
16k views

MySQL user permission on stored procedure

I've created a simple stored procedure: mysql> CREATE FUNCTION hello (s CHAR(20)) -> RETURNS CHAR(50) DETERMINISTIC -> RETURN CONCAT('Hello, ',s,'!'); Query OK, 0 rows affected, 1 ...
1
vote
2answers
6k views

MySQL: Delete all but last N records

Consider the following table: mysql> DESCRIBE pixels; +---------------+-------------+------+-----+-------------------+----------------+ | Field | Type | Null | Key | Default ...
9
votes
2answers
27k views

MySQL Set UTC time as default timestamp

How do I set a timestamp column whose default value is the current UTC time? MySQL uses UTC_TIMESTAMP() function for UTC timestamp: mysql> SELECT UTC_TIMESTAMP(); +---------------------+ | ...
3
votes
1answer
1k views

MongoDB - handling embedded documents and relations

I am researching MongoDB for a web app that I am bulding. Coming from a MySQL background, the concept of embedded documents is not so easy to fully understand. Let's say I have a document called ...
4
votes
1answer
851 views

How to use a relational database to store all users who belong to a group, and all groups which a user belongs to?

This is a beginner question: A user can belong to many groups, and a group can contain many users. Let's say the two tables look something like this: user_id user_name user_email group_id ...
1
vote
1answer
452 views

designing server side database to store user-specific data

I have a database with a number of quiz questions and answers. My basic design consists of these two tables questions (question_id, question_string); answers (answer_id, answer_string, ...
1
vote
1answer
386 views

query_cache tuning for a database server to keep db from slowing

I have a db server that that is a cloud slice of 512mb ram and 20gb disk. I wanted to make this run as fast as i can since it's the db for a magento insall on the app server. I turned on the ...
6
votes
1answer
13k views

High CPU usage from MySQL with no queries at all running

I noticed that MySQL is using way more CPU than usual on my workstation (usual is 1% or less, because this is my workstation, not a server). PID USER PR NI VIRT RES SHR S %CPU %MEM ...
4
votes
2answers
5k views

Primary key vs. unique index: performance difference with foreign keys?

Will there be any difference in performance if you compare a query fetching data via a join between two tables where there's a relationship against either of the following: A primary key A unique ...
0
votes
1answer
83 views

MongoDB: Can I perform a second query if the first doesn't match

When querying MongoDB is it possible to perform a query and if it isn't matched perform a second query. I could perform an $or which will do booth queries and return the results for booth but I only ...
2
votes
0answers
422 views

Why are runtimes different for a table including a primary key versus a table with a clustered unique index added after population [closed]

When I create a temporary table with a PK defined from the outset like this I get great performance in subsequent joins on that key: create table #temp ( field1 int not null field2 int ...
0
votes
1answer
60 views

Is index like key(timetime) usable when we query: SELECT * … ORDER BY timetime DESC

When we index a timestamp field like timetime. Can we use it for ORDER BY timetime DESC or is it just usable for ORDER BY timetime ASC OR ORDER BY timetime? Does mySQL use this index when doing vise ...
0
votes
1answer
600 views

Why do aggregate functions alter the way my rows are fetched?

Running this query SELECT s0.id, s0.symbol, YEARWEEK(p0.datetime) AS label, p0.id AS point_id, p0.datetime, KG_FIRST(p0.open, p0.datetime) AS open, MAX(p0.high) AS high, ...
4
votes
1answer
1k views

Oracle subquery column aliasing syntax?

I have something like: SELECT a, b INTO v_a, v_b FROM ( SELECT x, y FROM whatever UNION SELECT z, w FROM something ) AS subquery (a, b) Which of course doesn't work in Oracle ...
9
votes
2answers
10k views

Slow Performance Inserting Few Rows Into Huge Table

We have a process that takes data from stores and updates a company-wide inventory table. This table has rows for every store by date and by item. At customers with many stores, this table can get ...
5
votes
1answer
2k views

Using FLOATs with RAISERROR

I am using RAISERROR() to provide some basic Unit Testing functionality (as here), but I am frustrated by the inability to use FLOATs in the error message. I know I can cast the float to a string, but ...
15
votes
2answers
2k views

T-SQL query using completely different plan depending on number of rows I'm updating

I have a SQL UPDATE statement with a "TOP (X)" clause, and the row I'm updating values in has about 4 billion rows. When I use "TOP (10)", I get one execution plan that executes almost instantly, but ...
3
votes
1answer
289 views

All-or-none exclusive lock on 2 SQL tables

My simplistic testing suggested that I can acquire an exclusive lock on 2 tables or postpone acquiring the lock on either until both can be acquired at once by using a query like this: SELECT ...
5
votes
4answers
3k views

Script to generate insert statements

I am trying to write an SQL script to create an insert statement for each row of table TEST which has field A (int) and field B varchar(30), in my MS SQL database. I would like to save those insert ...
5
votes
2answers
2k views

Setting up filtering for server-side tracing

I'm trying to set up a server-side trace in SQL Server 2008 R2. While I have no trouble selecting events and data columns, the filtering seems a bit odd... I was trying to set up a filtering on both ...
7
votes
2answers
707 views

PostgreSQL PITR restore

I have a PostgreSQL 9.1 server running on a CentOS 5.8 32bit OS and I have enabled WAL archiving. On this server, there are three databases: databaseA, databaseB and databaseC. Someone deletes a ...
4
votes
1answer
1k views

SSIS Lookup Component Irregularities

I'm seeing odd behaviour in a dataflow with a lookup operation. If I select 'full cache' mode, some portion of the lookups are failing and I have no explanation why. 'No Cache' works correctly, as ...
2
votes
1answer
2k views

Can't create table or database in sql server as permission denied in database master . (Logged in with windows authentication )

Can't create table or database in sql server as permission denied in database master. Log in authentication is Windows authentication (./SQLEXPRESS)
4
votes
2answers
439 views

How to detach a sql server 2008 database that is not in database list?

I installed sql server 2008 on windows 7 then i create a Database! after 2 days, i reinstall the windows and isntall the sql server! now i am trying to attach my database file, bot i encounter to ...
2
votes
3answers
545 views

Maintain index on SQL Server table

My problem is how do I maintain an index on table, weekly we are deleting and inserting bulk amount of data from the table.Because drop and create index taking too long time..
3
votes
1answer
1k views

Daily database maintenance using SQL Server 2008 and a stored procedure

I have created a database maintenance plan using wizard though that link for SQL Server 2005. I have created a Maintenance Plan for SQL Server 2008 and it works fine. Now I required to complete the ...
3
votes
1answer
811 views

MySQL Handler_read_rnd_next == tablescans without indexes?

I am in the process of tuning our Percona 5.5 server, and have been using percona's tools to plot our database's performance. In the MySQL Handlers Plot, i have been noticing alot of ...
2
votes
1answer
991 views

SQL Server 2005 delete corrupt table

We are having a database in which one table name dbo.ONOA is corrupt. We need to delete this table. Please let me is there any way to force delete the table?
5
votes
2answers
2k views

Possible to keep max number of records in postgresql?

Basically part of our Postgresql table is used to keep server access logs, and as such sometimes during production this can get pretty large. is there any way of setting in postgresql to have a ...
1
vote
1answer
633 views

mongodb: replica-set processing reads on the primary

Running a replica-set with 1 primary and 2 secondaries, I wonder why the READs are also done on the primary. Shouldn't the primary mainly do the WRITEs and the secondary can share the READ-load?! I ...
-9
votes
1answer
317 views

What are the edges of typical (or specific) paid databases like oracle of mysql compared to the free oness? [closed]

Note: I am building a startup. I am currently using mysql. I am pretty much stuck. Others recommend other free databases like mongodb. I am seriously considering paid one IF and only IF it gets better ...
-1
votes
1answer
1k views

What exactly is SOLR? [closed]

It seems like a magical technology that can Do spatial search do full text search The problem is, It doesn't say where does it store all the data. Does it have it's own proprietary database If it ...
6
votes
2answers
1k views

Working Around Filtering Problems in Merge Replication

I am in the process of defining filters on a merge replication publication for our database. The problem I am coming up against is that merge replication has these rules, I don't like to call them ...
2
votes
1answer
11k views

What is different between SQL-Server versions 2008R2 and 2012

Dear SQL Server experts, Can you tell me the different between SQL-Server 2008 R2 and SQL-Server 2012 versions? I designed my product with version 2008 but when I tried to buy a licence, Microsoft ...
4
votes
1answer
1k views

How does SQL Server choose an index key for a foreign key reference?

I am working with a legacy database that was imported from MS Access. There are about twenty tables with non-clustered, unique primary keys that were created during the MS Access > SQL Server upgrade. ...
3
votes
2answers
2k views

How do I set the external editor for PostgreSQL's psql client?

What do I put in ~/.psqlrc file to set the default editor? The editor I want to use (Textmate) is at /Users/username/bin/mate. I found the place in the docs where they talk about it, and tried ...
1
vote
1answer
92 views

How can I automate sharding in the presence of continuous reads

I am using a pymongo in a sharded mongo environment. I have some fairly write-intensive systems, so I split the data up by time, with one database per hour, so the heavy-lifting of index-updates can ...
8
votes
3answers
3k views

Oracle: How do I query a Hierarchical table?

Background This is for the construction of some views we'll be using for reporting. I have an table of locations, the key fields being "location" and "parent". The structure that these two fields ...

15 30 50 per page