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)

4
votes
2answers
2k views

Does SQL Server have Date_Format function?

As title, does it? All I found is a list of predefined DateFormat that I can choose from, like this As I remember in MySQL (and PostgeSQL too?) you can defines your Date Format: i.e ...
1
vote
1answer
51 views

Database partition efficiency

Let's assume that you have a table that partitions on CATEGORY and SUBCATEGORY. Also assume that every subcategory can be mapped to a category, i.e. subcategory are proper subsets of categories. ...
3
votes
2answers
1k views

How can I optimize performance on a MySQL ndbcluster?

So, this is what I have: A simple table classes__to_students: |class |student| --------------- Math Alice Math Bob Math Peter Math Anne Music Bob Music Chis Music ...
5
votes
2answers
2k views

The order of INNER JOIN's

I would like to know if there are any rules about the order of INNER JOIN's in T-SQL 2000. I had 62x the performance on my query when my INNER JOIN that act like a filter is placed at first instead ...
1
vote
1answer
2k views

Copy blob from one row to another

I have a corrupt blob in a row. I'd like to replace that with another blob from the same table. How can I do that with sql statements only? (No file system access if at all possible.)
0
votes
1answer
116 views

TSQL - Bringing Data Together from Different Sources …refactoring PK and FKs

I have various offices and one central head office. Each office has its own SQL Server instance so each office has its own data set with its own set of IDs. Each office has already imported data ...
1
vote
1answer
148 views

Why isn't the result of an OpenQuery refreshing?

I'm trying to get some data from the Active Directory in SQL. I use the code: SELECT * FROM OpenQuery ( ADSI, 'SELECT objectGUID, objectSID, employeeID, lastLogon, mobile, telephoneNumber, mail, ...
0
votes
1answer
2k views

restoring a table from sql file in postgresql through Windows Command prompt

Im trying to restore an sql file which contains the dumpf a table (with COPY commands) into a table into the database, it would be great if someone could share an example, as the pg_restore doesn't ...
1
vote
4answers
4k views

Attaching MDF without LDF

I only have an .mdf file of my database which is not attaching. I am using the following command: EXEC sp_attach_single_file_db @dbname = 'Test_Data', @physname = N'D:\Test_Data\Test_Data.mdf'; ...
1
vote
2answers
356 views

Can I physically split a SQL Server database?

I seem to remember some time ago reading an article saying I could split a SQL Server database into more than one file, allow me to elaborate. I have a database that has a dozen or so tables that ...
0
votes
1answer
45 views

How can I disallow restore from backup on SQL Server?

I want to disallow restore from backup. How can I do this? One Of my friends said to me "Take a certificate for your database and anyone cant restore from your backup" I searched about ...
0
votes
1answer
1k views

sp_dts_getfolder isn't in my MSDB database, any ideas why?

We're currently moving our applications from a SQL 2005 to a SQL 2008 R2 database and everything has gone well(ish) but now one of our applications calls a stored proc called sp_dts_getfolder which is ...
0
votes
1answer
3k views

Oracle SQL for left outer join to rownum = 1 of another query?

Background I have a query joining many tables together, the chief of which is a workorder table. I also have a table called WOStatusHistory, which stores every status for every workorder. A diagram ...
0
votes
1answer
1k views

Who changed the job schedule on a SQL Server Agent Job (SQL 2000)

Someone (or some unknown process) changed the job schedule on a SQL Server Agent Job on a SQL 2000 database. The original start time was 6:00, but was changed to 4:45; that much I can determine. Is ...
9
votes
2answers
425 views

How many Sproc Parameters is too many?

I've just started writing a Stored Procedure in SQL Server 2008 and have 30+ parameters. I've never written one with more than ~10 parameters, and that got me thinking... At what point are there too ...
6
votes
2answers
1k views

When is a result returned deterministic and when not?

if you execute a statement like this: select first field1, field2 from exampleTable where field1 = '1'; then you get a warning like this: The result returned is non deterministic SQLCode=122 ...
6
votes
3answers
3k views

What is the best and easiest way to turn off SQL Server when not in use?

Situation: developer workstations that typically just use the client tools to connect to other non-local sql servers. However, there are rare times that having the full version of sql server to do ...
4
votes
2answers
424 views

how to get unique records

Table structure CREATE TABLE [dbo].[Order Details2]( [OrderID] [int] NOT NULL, [ProductID] [int] NOT NULL, [UnitPrice] [money] NOT NULL DEFAULT (0), [Quantity] [smallint] NOT NULL ...
2
votes
3answers
932 views

SQL Analysis Services - SSAS

Do you know what the best practices would be regarding SSAS and having real-time reports. I am not sure if we should be pulling data off our live database or using SSIS to move data periodically to a ...
0
votes
3answers
946 views

Oracle returns different results when executing a sql with bind variable or with a fix value

The following two statements (strongly simplyfied) returning a different result: with a fix value for rownmun: select * from table where rownum <= 12; with bind variable for rownum: select * ...
1
vote
1answer
1k views

Heterogeneous queries error using stored procedure

Stored procedure ALTER PROCEDURE Proc_DayShift AS insert into #Punching_History SELECT * FROM SERVER2.MARS.DBO.TABLE1 GO SET QUOTED_IDENTIFIER OFF GO SET ANSI_NULLS OFF GO SET ANSI_WARNINGS OFF ...
1
vote
1answer
326 views

how to transfer data from table to table

I have two tables Table1, Table2. From Table1 want to transfer data to Table2. Suppose I have the following query: Select * from Table1 where UserID between 5 and 10 I want to store above ...
4
votes
2answers
998 views

How can I speed up a query that orders by a calculated field?

I will try and give an example - this is not my table structure - I'm simply trying to outline the issue in order to find a solution... Person Id, Name BrothersNames Id, Name SistersNames Id, Name ...
6
votes
3answers
5k views

Executing Stored Procedure that accesses another SQL instance

I apologize if this question repeats another already asked. I have searched for hours and have not found one that fits my situation. Desired Outcome A user using SQL authentication has execute ...
2
votes
3answers
1k views

SQL Server Max number of Times a table can be referenced as a foreign key?

Is there any maximum on the number of times a single table can be referenced in a SQL Server database via foreign key? IE Table A A_ID Table B ~ B_ID, A_ID Table C ~ C_ID, A_ID Table D ~ D_ID, ...
8
votes
3answers
2k views

SQL Server - Multiple running totals

I've got a base table with transactions and I need to create a table with running totals. I need them to be per account and and also have a few running totals for each account (depending on the ...
1
vote
5answers
482 views

Frequent or Infrequent Commit

I'm trying to run an update query but still taking to long I have a commit in it. Is it better to set the commit to a higher value (5000) or lower (1)? I have to update 15 million records in a table ...
1
vote
1answer
508 views

Insert 4 tinyint values into varbinary(4)

I'm working on a function to convert the string representation of an IP into its varbinary(4/16) form. Right now, I have this: @stringIP = '192.168.0.3' select CAST(PARSENAME(@stringIP, 4) as ...
2
votes
1answer
157 views

Suggestions for SQL query repair tool or tips on building one?

Not sure if this is ontopic so I figure I would ask here and if its not liked then we can close it. Our hosting provider for a legacy application that I inherited is no longer supporting Oracle 10 ...
3
votes
1answer
520 views

Theta join explanation

Given the following question, I'd be glad if someone could help me. Take the following relational schemes: R(A, B , C) S(D, E, F) where A and D attributes are the primary keys. Assume to ...
0
votes
0answers
354 views

Oracle Flashback Archive aka Total Recall in MySQL

What would you suggest as a replacement system to achieve the same functionality of Oracle Flashback Archive aka Total Recall in other DBMS, in general or specifically in MySQL or MariaDB? ...
0
votes
1answer
347 views

Returning Multiple Result-Sets or Single XML Blods

I've been writing some new Stored Procedures, and find myself returning between 6-8 result-sets in a few cases. I've always worked under the assumption that there were certain inefficiencies with ...
4
votes
1answer
2k views

SSIS how to parse column with erratic data

I have a question on how to parse out a column and hoping a SSIS/Database guru can help out :) Here is the problem. I have a column saved as a string/varchar format in SQL Server, and need to parse ...
3
votes
2answers
4k views

Can someone explain why select with nolock will query a potion of updated data?

I was reading the answer from here (from stackoverflow, I think should ask in here) NOLOCK means placing no locks at all. Your query may returns portions of data as of before UPDATE and ...
1
vote
1answer
603 views

How to implement an effective ACL/auth in a relational db?

We are looking at implementing an ACL that fulfills the following requirements: Most users have access to an item (access to the item by default), but a few is denied access. Most users do not have ...
3
votes
1answer
3k views

Sql. Calculating the size in KB of each row

I'm building now a new sql 2005 database for my company, and we expect this database to be huge with 100's of millions of records. We already know we need to dedicate a separate server with new hard ...
0
votes
3answers
41 views

helping hand for sql server resources

I'm just getting into SQL-SERVER, so forgive me if this is a basic question. I need help, recently work on database programming, For my query development, to understand complex query, to can ...
1
vote
1answer
978 views

Recover PostgreSQL database data

I am using PostgreSQL in my project, Now by mistake I have deleted some records of one of my tables. Now is there any way to recover deleted Records in PostgreSQL?
1
vote
1answer
131 views

Is it possible to allow write-through computed columns for legacy code that expects a column to be read/write?

I have this existing table for IP storage: CREATE TABLE [dbo].[IPAddresses]( [ID] [int] IDENTITY(1,1) NOT NULL, [IPv4Address] [varchar](15) NULL, [IPv6Address] [varchar](45) NULL, ...
2
votes
2answers
478 views

SQL Joins Order of Operations

I'm new to SQL but happen to be dealing with a couple of rather larger table (on the order of a billion rows each). I want to do an inner join like the following: SELECT * FROM XTABLE X INNER ...
2
votes
1answer
1k views

Found important issue with SQL Server 2008 R2. Need Advice

Recently while installing my copy of SQL Server 2008 R2; the power went OFF. So now it does say the some features are installed and some are not but when I run SQL server detection manager it says ...
1
vote
2answers
5k views

Select multiple rows from one row based on column values

I have a product table where the value of two columns can imply either one or two actual product results. If column X = 1 AND Y = 0 return one result, if X = 0 and Y = 1 return one result, if X = 1 ...
4
votes
2answers
1k views

Query execution showing error as login failed

I want to retrive the table values from other server Query EXEC sp_addlinkedserver @server = 'OPSERVER', @srvproduct = 'SQL Server' EXEC sp_addlinkedsrvlogin @rmtsrvname = 'OPSERVER', @rmtuser = ...
1
vote
2answers
6k views

Exporting table records to an INSERT script

I'm setting up a test environment for development and need to export some static data from tables in Production. Ideally the exported product would take the form of a script with all the required ...
2
votes
2answers
1k views

Update column by comparing date and string values together

I have problem in updating table. I need to update table by comparing date and name with another table. I have two tables: table 1 : dim_sesid name(varchar) role ...
0
votes
1answer
311 views

Implementing Pub/Sub initiated from the database

I have a number of state-full Windows Services that currently poll the database looking for new or changed records in specific Tables and/or Views. For obvious reasons this limits scalability and is ...
0
votes
2answers
158 views

MOM and EOM in SQL Server 2005

What is the most sample and practical way to know the MOM (middle of month) and EOM (end of month) in an store procedure on SQL Server 2005? (without doing a select case / switch) EOM is the last day ...
2
votes
3answers
2k views

Easy or Schedulable way to move data from Production to Test

What I am looking to do, is schedule a copy of data from my production database to my dev/test database. The dev/test database will be newer than the production database in terms of schema, but the ...
2
votes
1answer
328 views

Is staggering reindexing jobs a good strategy?

I have inherited a server with 35 databases and a job that reindexes all tables on all databases (using sp_MSForEachTable). It's taking over 14 hours to complete and is now blocking other processes. ...
2
votes
1answer
494 views

high 'total_worker_time' for stored proc using OPENQUERY in SQL Server 2005

I have a stored procedure in SQL Server 2005 (SP2) which contains a single query like the following (simplified for clarity) SELECT * FROM OPENQUERY(MYODBC, 'SELECT * FROM MyTable WHERE Option = ...