An acronym for "Structured Query Language" (it's not the name of a specific DBMS product), SQL can be used in relational database management systems (RDBMS) to query, update, delete, and insert data as well as modify the structure of the database. It can also be used to manage schemas and data ...

learn more… | top users | synonyms (1)

0
votes
1answer
40 views

Relationship between two tables so their value changes together

First of all I'm not sure if this website is for purely experts but sorry if it is.. the main page was a little vague I was wondering if it'd be possible to have a relationship, for example, in my ...
0
votes
1answer
48 views

Script not emailing from Maintenance Plan/SSIS

I have created the following script to send emails from my plan but it isn't sending out. It works correctly in a query window and under an agent job. This is added to the plan as a 'Execute T-SQL ...
1
vote
1answer
45 views

MySQL: Find ID with only 2 attached IDs in subtable

I've got 2 tables. 1 containing my Threads and 1 containing the users attached to these threads. I want to find the ThreadID with 2 specific UserIDs attached, no more no less. This is what I've come ...
0
votes
0answers
60 views

Show single value of one column for multiple rows of other columns

I have a SQL query which displays my data results like this. date emp_id emp_name spent_hours 19-08-2013 1024 jack 10 19-08-2013 1024 jack 11 19-08-2013 1024 jack ...
1
vote
5answers
203 views

What is the advantage of partition Date field into individual Year(int), Month(int), Day(int), Time(time) columns? [closed]

What is the advantage of partition Date field into individual Year(int), Month(int), Day(int), Time(time) columns? My manager said this is well known practice and query performance is good. Is this ...
2
votes
2answers
417 views

Is there any way to do a SELECT query without any optimization in SQL Server?

I am trying to test the speed of SQL server queries. However, once I do the query once, it becomes a lot faster. The database is live so I can not make any changes to it, only to the SELECT query ...
1
vote
0answers
22 views

How to cope with SQL Server 2012 vs SQL (Azure) Database sql files

I'm trying to port my system to SQL Database (Azure instance) from SQL Server 2012. I'm using Visual Studio 2013 and I have my .sqlproj with all the definition of my database inside. Given that a ...
0
votes
1answer
145 views

MySQL 5.1 -> 5.6 problem, select distinct order by limit query stops using index

I'm testing a MySQL 5.1 -> 5.6 upgrade, and I've run into an issue. I have a query that hits a ~30 million row table, selecting distinct IDs with an order by/limit restriction. Sample query is ...
0
votes
0answers
35 views

I am trying to implement Scott Chamberlain's code in SQL Server 2008 R2 . Getting Assembly not present errors

I am trying to use Scott Chamberlain's code, here: http://dba.stackexchange.com/a/17466/45380 I was able to compile it and create the DLL, but now when I try to run SQL CREATE ASSEMBLY I get: Msg ...
0
votes
1answer
48 views

Need to delete consecutive, unchanged records

I have a rather large MySQL db that is tracking pricing changes for a large number of products. Each entry has a SKU a datetime and a price. Sometimes, there is no change in the price from one time ...
0
votes
1answer
38 views

CASE conditions in SELECT statement [closed]

I have the following SELECT statement: SELECT expt_id, iso_stain, test_stain, stain_type CASE WHEN stain_type = 'Blue' THEN iso_stain = 'NA' CASE WHEN statin_type = 'Hematoxylin' THEN ...
0
votes
2answers
46 views

Query with a sequence of “and not like”

I have a table called VHS_Metadata_Aug52014 with columns: Title, Description,Tag, Speaker, VIP, FilmingLocation, Notes I'm trying to write a query that returns all records for which the word ...
3
votes
2answers
220 views

Can I update every datetime in bulk?

The current database assumes all times are local to the user. Now we're changing this so the database stores everything in UTC and our application converts the UTC time in the database to the correct ...
0
votes
1answer
32 views

Sub query with not equal

Sub query with not equal table_1 col1 SV0362 RU0177CSPG NO0124CSPG VN3582 AT9923CSPG BZ0324 PE0309 AS4293EXPT ML0331OMKT table 2 colA OO56128665 OO56128665 OO56128665 OO56128665 US0170 US0170 ...
0
votes
1answer
52 views

JOIN on Microsoft Access derived table not working

Can you please help me why my below SQL is not working in Access 2010? SELECT Table2.Product, Table2.Color, SEQMAX, Table1.Attribute FROM ( Table2 LEFT JOIN ( SELECT ...
0
votes
2answers
87 views

SQL insert into … values (…, select(…))

I am trying to insert 25 users, user1...25 into Members with the same GR_ID = 2 with command: insert into MEMBERS (GR_id, username) values (2, (select username from USERS where username like ...
0
votes
0answers
21 views

Access Sql Server Linked Server during Logon Trigger

I am trying to log users logons to my Sql Server (A) in another Sql Server (B, different location physically), but when I try to log in I get the error Login failed ... due to trigger execution and ...
1
vote
0answers
108 views

sql query takes too long to execute [closed]

I am having trouble with this query. It takes 10 hours to execute. WITH CONSUM AS ( SELECT C.ID_MEASURER,C.ID_MEASURING_POINT,C.CONSUM_TYPE FROM GCGT_RE_CONSUM_H_E C WHERE C.DAY ...
1
vote
0answers
32 views

One table for article comments, video comments and photo comments or multiple tables?

First DBA question. Greetings people. I hope I'm not duplicating a question but it's very hard finding database design related questions here (for multiple comment tables), as all 'design' questions ...
0
votes
2answers
81 views

How to deal with very large transaction logs in SQL Server

Here is my situation: I have being asked to deal with a SQL Server 2008 R2 database that has a transaction log that is several times bigger than the database itself. The database is in full recovery ...
0
votes
1answer
58 views

User defined data types causing implicit conversions

user defined datatypes, i'm looking at some execution plans and seeing implicit conversions happening in the background when a var is declared of type user defined data type and pulling a value into ...
3
votes
4answers
218 views

Best practice for a Table with private columns

I have a table with user data, where most of the columns can be public or private (so it will be shown or not on the app) and every user can decide which fields to hide. So far I had a couple of ...
0
votes
1answer
42 views

Compare dates in Oracle SQL [closed]

I have a table LoanDeadline that has a column called deadline, it's simple text and not Date and it's in the format of July 25, 2014 How do I compare this with sysdate ? So far I have SELECT ...
0
votes
2answers
36 views

assign selected columns to a variable

Select sum(column_a) as a, sum(column_b) as b round(a / b) From table Group by column In the example above I am summing two column, and I would like to use those 2 results in calculating ...
0
votes
1answer
58 views

How do I count the number of different child id's belonging to a parent record?

For instance I have two tables in a music database. Table album and table track. Each track record has (amongst other things), an album_id and an artist_id Each album record has a unique album_id ...
1
vote
1answer
40 views

Does PostgreSQL allow multiple grantees in GRANT commands?

Looking at the PostgreSQL docs it seems that the GRANT command only grants to a single user or role. In fact it doesn't seem to be PostgreSQL alone. Isn't possible to do something like GRANT SELECT ...
-3
votes
3answers
82 views

SQL cache hit ratio [closed]

I have install SQL server, but when i check report of DB there is cache hit ratio which is 98.92%. Is it harmful for sql, if yes then how to reduce it.....? please give me solution for that. thanks, ...
0
votes
3answers
66 views

Suppress display in a column if the value is equal to the value in another column

I have 2 date columns that display side-by-side. I have some dates that are equal. I do not want to display the "equal" dates/duplicate date values in one of the columns. How do I do that? Example ...
0
votes
1answer
44 views

Script to Add a Job to a SQL Server DB

I want to add a job to my DB to make a back up weekly but i want to do it from an script, i've serched and with what i found i made this: CREATE SCHEMA job go CREATE PROC BACKUPS @dir varchar(max) AS ...
1
vote
1answer
38 views

Combine 2 tables

I am wanting to combine 2 tables. until recently the column names were different , and one had fewer columns than the other, however it was deemed unnecessary to have them as two tables. I have ...
0
votes
1answer
33 views

SQL where clause effect on table? [closed]

I have sql query as select sourceIP, sum(sourceBytes) from flows group by sourceIP order by sum(sourceBytes) desc This brings result (dummy) as:- sourceIp SourceBytes 192.168.1.2 100 ...
3
votes
1answer
23 views

Postgresql query plan differs with limit value making the query slower for lower limits

I have this query: SELECT "table_1".* FROM "table_1" WHERE "table_1"."deleted_at" IS NULL AND "table_1"."table_2_id" = 15797104 ORDER BY "table_1"."id" ASC LIMIT 1 The explain for the query ...
0
votes
1answer
36 views

MySQL Insert with Select

Trying to insert data to a table with values from different tables. INSERT INTO class_teachers_section(class_ref, teachers_ref, section_ref) select (select class.id as class_ref from class ...
2
votes
2answers
82 views

Should I drop a foreign key if I use a soft delete?

"ON UPDATE" scenario never happens in my application. As soft delete is used, "ON DELETE" cascade and restrict scenario never happen as well now. Then, should I just drop foreign key because I have ...
0
votes
0answers
51 views

Implicit conversion from data type varchar to varbinary is not allowed. Use the CONVERT function to run this query

While I am executing a query, I am getting the below error: Implicit conversion from data type varchar to varbinary is not allowed. Use the CONVERT function to run this query My query is: ...
0
votes
1answer
46 views

Is it possible to create a function in SQL server to act as clause e.g. Where or Limit

I've found a simple way to mimic the limit clause is SQL server by using SELECT * FROM customers OFFSET 22 ROWS FETCH NEXT 5 ROWS ONLY I'd like to replace those two line with LIMIT(22, 5) e.g. ...
1
vote
1answer
57 views

add a column to an existing table

I'm wanting the best way to add a column to an existing table in my database. I'm using SQL Server 2012. I don't want the data that is in the table to be affected, I just want to add a new column ...
0
votes
1answer
43 views

change column name

I'm needing to update a few column names in some tables I have in my database. I'm using SQL Server 2012. I'm aware of using the RENAME ability: ALTER TABLE table_name RENAME COLUMN old_name to ...
1
vote
1answer
79 views

Selecting data from multiple rows and insert it into a column

My table is like this: temp1 name city phone_no pincode ----------------------------------- amit Delhi 12345 123 Rajiv Bombay 836536 432 How do I transform the last ...
0
votes
2answers
60 views

Set default value for all columns with specific name within a database

I've got a database that includes an int column project_id on many tables, and I want to script setting the default value to a specific value for all columns with that name in the database. Note that ...
0
votes
2answers
10 views

Prevent auto commit of DROP without SET AUTOCOMMIT OFF

I dropped my table and I lost my data and I can't roll it back because DROP statement automatically commits. How can I prevent auto commit action of DROP without using SET AUTOCOMMIT OFF?
0
votes
1answer
36 views

How to install/enable DAX functions in SQL Server [closed]

How to install/enable DAX functions in SQL Server? I want to pivot and use some Excel functions in SQL Server
0
votes
1answer
89 views

MySQL select with left join query

I have following code. select class.name as classname, class.hours as hours, teachers.first_name as teacherFirstName, teachers.last_name as teacherLastName from teachers,class left join ...
1
vote
1answer
100 views

MS Access query-by-form opening query, but not running it with new form data

I have created a query-by-form in MS Access. The form has a text field for each field in my table. I'm only using one starting out to test. The query criteria for that field is Like "*" & ...
1
vote
1answer
22 views

How to apply a newly-created Domain to an existing Column?

In Postgres 9.4 Beta 1, I successfully created a domain of type VARCHAR, fuel_domain_. The domain checks that a value is any of 5 possible strings, coal, gas, wind, hydro, other. CREATE DOMAIN ...
2
votes
0answers
92 views

Split comma separated entries to rows

I have a Table like this: | ID | OtherID | Data +--------+-----------+--------------------------- | 5059 | 73831 | 5103,5107 | 5059 | 73941 | 5103,5104,5107 | 5059 | 73974 | ...
0
votes
1answer
25 views

move content from one table to another table and add a new value

I need to move content from one table to another table, this part is done: INSERT INTO `insc_mwc` (`nome`,`empresa_idempresa`,`cat_mwc_idcat`,`points_pontos`,`n_registo`) SELECT ...
0
votes
1answer
75 views

How to select non unique values from 1 column if a value doesn't exist in column 2

I have a table containing (among other things) 2 integer values, neither of which are unique. See below for example data: --------------- | a | b | --------------- | 1 | 1 | ...
3
votes
2answers
144 views

Pagination with PostgreSQL 9.3: counting number of pages

I'm implementing pagination and sorting of rows in, let's say, products table, using multicolumn index on category, score and id. -- index create index category_score_id on products(category, score, ...
1
vote
1answer
59 views

MYSQL Query - Unexpected result in text messaging database [closed]

On a text messaging database I have built, I am trying to return the total amount of messages a user has sent and the total number of messages a user has received. I have the following code: SELECT ...