SQL Server 2008 (major build version 10.00.xxxx). Please also tag with sql-server.

learn more… | top users | synonyms (2)

1
vote
2answers
197 views

Which data type should I use to store a 11 digit number [closed]

Which data type I should use to store an 11 digit number? It must store '0' as the first digit. For example, if I store 02421402015, it must show 02421402015. I tried using varchar and it shows ...
5
votes
4answers
590 views

The column order of composite clustered primary key on a partitioned table?

I have the following table. create table T (K1 date, K2 int references S(Id), ....) on partitionScheme(K1) The table will be partitioned by K1 (K1 has low selective. the data will be appended in ...
4
votes
2answers
16k views

SQL query that concatenates values from duplicate rows in a single table

Let's say I have a table of employees, like this: Name Sex Role Bob M Developer Joe M QA Now, I have a problem with duplicated rows in this table. I will fix it ...
17
votes
3answers
6k views

Dynamically Define a Range in a Dimension

I have an issue that I face every time I decide to build a cube, and I haven't found a way to overcome it yet. The issue is how to allow the user to define a range of things automatically without ...
12
votes
4answers
31k views

How to view an encrypted view or stored procedure

I am working on a third party database. When I try to view the definition of a view by right clicking, CREATE TO and then to NEW QUERY EDIT WINDOW, I am getting an error: This property may not ...
7
votes
1answer
1k views

SQL Server not giving back memory - staying at Max Server Memory setting

I'm the only one working on this server and followed documentation about optimizing SQL memory usage when I saw that SQL was using all of the memory available of the server. One of the steps I did is ...
15
votes
3answers
7k views

Schema design - best practices?

I understand the capabilities of SQL Server Schemas, but what are the best practices? Sure they give another layer of security, and provide logical grouping of database objects within the database, ...
1
vote
2answers
758 views

SQL Server Linked Servers and Remote Statistics

I'm trying to get a better understanding of how SQL Server uses statistics on remote SQL Servers (e.g. a Linked Server). I understand that the user needs db_owner/db_ddladmin rights to be able to use ...
5
votes
2answers
15k views

Restore Backup Fails - File 'Db' cannot be restored to '{…}.mdf'. Use WITH MOVE to identify a valid location for the file

I am getting the following errors trying to do a restore using the restore command on a backup file I recieved from a customer. RESTORE DATABASE SFDB FROM DISK = N'C:\Backup\Backup.bak' Any ...
25
votes
2answers
5k views

Using EXCEPT in a recursive common table expression

Why does the following query return infinite rows? I would have expected the EXCEPT clause to terminate the recursion.. with cte as ( select * from ( values(1),(2),(3),(4),(5) ) ...
3
votes
1answer
69 views

Delete User View named the same as system view

I am exporting a database to Azure and have found a user view created in a previous version of MSSQL (Currently running 2008) that is name INFORMATION_SCHEMA.TABLE_CONSTRAINTS which obviously should ...
1
vote
2answers
4k views

Insert Missing Dates from a query

How can i insert missing dates from a query i created. The result below: Date Frequency 2014-05-18 5 2014-05-20 7 2014-05-25 7 2014-05-27 6 I want the result to have missing ...
0
votes
2answers
33 views

text positioning for select list

I have following issue, I have hierarchy table where every record has level, code and description and I need to have description to look as it is was one column. Example code CREATE TABLE #tmp (...
0
votes
2answers
1k views

How to remove orphaned Log Reader Agents from Replication Monitor?

How do I remove the two Log Reader Agents with errors from the Replication Monitor? As you can see, the job does not exist (Error message produced by right click > Properties on errored Log Agent ...
9
votes
4answers
72k views

I can't connect to my servers SQL database via an IP Address

I have setup a server that runs Windows Server 2008, and has SQL Server 2008 Express installed. I can connect to the machine's SQL Server Express database via the MACHINENAME/SQLEXPRESS. However ...
6
votes
3answers
10k views

Connect to SQL Server 2012 from an Windows XP client

We have an SQL Server 2012 Standard database, to connect to it we use SQL Server 2008 Management Studio (since 2012 SSMS is not supported on Windows XP). The problem is that SQL Server 2008 gives all ...
5
votes
2answers
5k views

Error Querying MySQL server linked to SQL Server 2008

I've created a linked server in MS SQL Server 2008 to a remote MySQL server. When I try to query any tables, I get an error: .tablename. contains no columns that can be selected or the current user ...
1
vote
2answers
51 views

User cannot select from table but their permission appear to show that they should be able to

I attempted to revoke delete permissions to most users in a database by using the deny and revoke sql commands and checking the deny box for delete when adding the table as a securable in the UI. ...
1
vote
1answer
1k views

Creating indexes with t-sql scrips vs rebuild indexes in maintenance plan

I’m using SQL Server 2008 and I am running several (15) scripts each day to bulk insert to tables. Each script drops the table at the beginning. I create indexes in the scripts. Some of the scripts ...
8
votes
1answer
22k views

SQL Server 2008 R2 high Buffer I/O causes

Am trying to troubleshoot performance on a SQL Server that we have for our document management server and today performance has hit an all time low. Looking at the Management Data Warehouse (MDW) I ...
0
votes
1answer
70 views

Index Maintenance Plan

At our organisation we are migrating to SQL Server from visual foxpro dbf and hence had no maintenance plans and have no DBA. We have gone through our backup plans and Index maintenance is only index ...
2
votes
3answers
90 views

Join between different frequency tables

Assume that I have two tables, DailyTable and QuarterlyTable, where each have 3 columns: ID, Date, and Value. As the names indicate, the frequency of data stored in DailyTable is daily, while the ...
5
votes
2answers
26k views

Granting Execute Permissions on Stored Procedures, Functions and Views

I am using a user which has read permission only. It basically has permission to Connect Execute However, it does not have execute permissions on Functions and Stored Procedures. In part of my ...
0
votes
2answers
49 views

Create a copy of a SQL Server Job

Using T-SQL or Powershell, how can I create a stored procedure that performs the following: Copy a SQL Server Agent Job to another backup Job on the same server (with a new name) Disable the backup ...
4
votes
1answer
3k views

Windows native backups makes SQL Server think that databases backup has been done

community. I've Windows Server 2008 R2 which hosts few virtual machines. One of machines is Windows 2008 R2 server with SQL server 2008 R2 Express installed. Here's the thing: I wrote a script that ...
6
votes
2answers
43k views

Primary filegroup is full SQL Server 2008

I have a large table (~50 million rows) I'm trying to bulk insert into SQL Server and I get the error: Could not allocate space for object 'myDB' in database 'I 3 Stroke' because the 'PRIMARY' ...
4
votes
3answers
25k views

SQL Server 2008 Database Restore Error - Cannot open backup device 15105

I am trying to restore from a backup and getting the following error Msg 3201, Level 16, State 2, Line 1 Cannot open backup device 'Z:\FULL_BACKUP.bak'. Operating system error 3(failed to ...
0
votes
0answers
39 views

Bypass or Override SQL Server DB related error during WSUS Setup Installation?

When trying to install the latest WSUS release from here: Windows Server Update Services 3.0 SP2 We tried it once with the DB and then someone suggested detaching the DB and moving to another drive ...
7
votes
1answer
155 views

Two columns with and without index in where clause - How index works

I am executing a query on SQL Server 2008: SELECT col1 FROM table1 WHERE col2=val2 AND col3=val3 Here col2 has a non-clustered index, col1 is the PRIMARY KEY, and col3 does not have any index. ...
0
votes
0answers
31 views

Why are schema changes I've made reverting?

I have been experiencing issues when making schema changes/stored proc definition changes. The changes that I make are not always persistent. I can make a change today then a day or two later I'll ...
0
votes
1answer
42 views

SQL Server accepting Access queries?

I am currently working on migrating a legacy codebase from VB6 and Access to VB.NET and SQL Server. I have run the Microsoft SQL Server Migration Assistant successfully and populated a SQL server ...
0
votes
3answers
82 views

How to check if range between two numbers is available in table of ranges

I have following table of number ranges Create table Ranges { Id int identity(1,1) primary key, RangeFrom int not null, RangeTo int not null } Insert into Ranges(RangeFrom, RangeTo) VALUES (1,...
0
votes
1answer
47 views

Query distinct emails not logged in within a period of time

I need help in writing a query to return distinct emails that have not logged into ABC database in the past 5 months. The exact task I have been asked is as following: Create a table in ABC ...
1
vote
2answers
4k views

Calculate time difference between a datetime and the current date & time

I would like to calculate the difference between a past datetime and the current datetime with the result in [hh]:mm format.
1
vote
1answer
7k views

Standard data types for email address, telephone number , first name, rixh text editor, etc

I want to build a database for our system using Sql Server 2008 R2. but i need to know what are the best data types for storing these info:- Email address Telephone number with extension, such as +...
18
votes
7answers
466 views

Group daily schedule into [Start date; End date] intervals with the list of week days

I need to convert data between two systems. First system stores schedules as a plain list of dates. Each date that is included in the schedule is one row. There can be various gaps in the sequence ...
3
votes
3answers
914 views

Can the OUTPUT clause create a table?

I'm doing an update like this: UPDATE dbo.Table1 SET BirthDate = b.BirthDate FROM Table1 a JOIN Table2 b ON a.ID = b.ID And I want to use the OUTPUT clause to back up my changes. UPDATE dbo....
1
vote
1answer
58 views

Slow-running query returns incomplete resultset

So I'm trying to get some data from an SQL Server 2008 instance, the query is quite simple in structure but it has an extremely poor performance, it takes just under a minute to retrieve a bit over 1,...
7
votes
1answer
163 views

Should we still be using QUOTENAME to protect from injection attacks?

I was looking at an old stored procedure today and noticed it was using quotename on the input parameters. After doing some digging to figure out what that does exactly I came across this site. I now ...
3
votes
2answers
241 views

Why database snapshot creation is faster than normal database backups?

Could you tell me any reason why creation of database snapshot is faster than database normal database backups in MS SQL server
1
vote
1answer
43 views

sql getting sum of calculated columns

How can I get the sum of TotalAmount as single value for example Product Name UnitPrice Quantity Discount% Amount SharingCost% ShippingCost CustomsCost TotalAmount pro1 250....
4
votes
1answer
130 views

When executing a command via xp_cmdshell what user issues the command to the system?

I'm executing the following command to stop a service on a remote server from within a stored procedure in SQL Server. ---------------- -- Stop Service ---------------- SET @Command = 'sc \\' + @...
15
votes
4answers
4k views

Anybody using HierarchyId in production? Is it reliable?

Is anybody using HierarchyId in real production with tables of reasonable size, more than a few thousand rows? Is it reliable/performant? So far I have not found anyone not affiliated with the vendor ...
2
votes
1answer
45 views

msdb.dbo.sysjobs and last run date and time

I know that the last_run_date and last_run_time are stored as Int, but when coverted over to datetime (of which I have examples of), is the time GMT, or what? When converted it doesn't match the same ...
0
votes
0answers
15 views

Would snapshot replication avoid the “repl table shuffle” when making schema changes?

I support an application that sits upon a SQL 2008 database and has an admin tool that allows app admins to do some field customization. This issues an ALTER TABLE command when saved, and since the ...
0
votes
4answers
972 views

SQL Query Declaration problem

I have a view as shown below.The View is good running.When I attempt to run view,I got the following the error.What might the problem? Incorrect syntax near the keyword 'Declare' SQL Query: create ...
4
votes
2answers
98 views

The index columns in sys.index_columns different from what are in the index

When I run the following I get 3 indexed columns: SELECT b.name, c.name FROM sys.index_columns a INNER JOIN sys.indexes b ON a.object_id = b.object_id AND a.index_id = b.index_id INNER JOIN ...
1
vote
1answer
92 views

Most efficient way of finding rows in a table that don't exist in another — SQL Server

What is the best method of finding rows in table A that don't exist in table B based on unique key of the tables, when both tables are huge (A over 300 million rows, B over 500 million rows) and the ...
0
votes
0answers
15 views

Connect MSSQL DB with SSAS

I am trying to build a BI system using SQL Server 2008. I have installed and created the database. I have also installed SSAS but I can't seam to find a way to connect my database as a Data Source ...
1
vote
0answers
28 views

Problem inserting into table from trace file consumes all space in tempdb

I'm working with SQL Server 2008 SP3 Enterprise Edition (64-bit) I'm trying to import a trace file of about 3.5 MB (4667 rows) into a table as following: INSERT INTO DBTRACE with (rowlock) SELECT * ...