Most Popular

1500 questions
26
votes
2 answers

Changing a column from NOT NULL to NULL - What's going on under the hood?

We have a table with 2.3B rows in it. We'd like to change a column from NOT NULL to NULL. The column is contained in one index (not the clustered or PK index). The data type isn't changing (it's an INT). Just the nullability. The statement is as…
Randy Minder
  • 2,002
  • 4
  • 21
  • 39
26
votes
20 answers

How to dive into an ugly database?

I'm sure many of you are/were dealing with a ugly database. You know, that database that isn't normalized at all, that database where you have to do a large painfully query to get the most trivial data, that database that is in production and you…
eiefai
  • 1,874
  • 2
  • 21
  • 18
26
votes
2 answers

Best way to migrate a huge SQL Server database with low downtime over network

Problem definition Our database server needs to be transferred to an other datacenter. It runs on Microsoft SQL Server 2012 Enterprise (64-bit) and contains two databases of about 2TB and 1TB. Having little to no downtime for this would be…
Val F.
  • 363
  • 1
  • 3
  • 6
26
votes
2 answers

Slow index scans in large table

Update 2020-08-04: Since this answer is apparently still being viewed regularly I wanted to provide an update on the situation. We're currently using PG 11 with table partitioning on timestamp and are easily handling a few billion rows in the…
Exelian
  • 429
  • 1
  • 6
  • 10
26
votes
2 answers

PgAdmin III - How to connect to database when password is empty?

I have installed PostgreSQL 9.1 on my PC (Win 7). I have a small Java application connecting successfully to it with login=sa and password="". The connection works. However, it is refused from PgAdmin III itself. I get: Error connecting to the…
Jérôme Verstrynge
  • 1,461
  • 5
  • 22
  • 27
26
votes
4 answers

Truncated 200GB table but disk space not released

I have only 2GB left, so I need to remove this history table. This table now is empty but the database disk space not released. And the database file is 320GB.
26
votes
3 answers

Check progress of alter index reorganize / rebuild

How can I check the progress / status when I submit an alter index reorganize / rebuild ?
nojetlag
  • 2,877
  • 9
  • 33
  • 42
26
votes
3 answers

What is the difference between a primary key and a superkey in a DBMS

What is the difference between a primary key and a superkey in a DBMS? Can a primary key and a superkey both have multiple columns? Is a primary key a subset of a superkey or vice versa?
MikeHil
  • 369
  • 1
  • 3
  • 3
26
votes
1 answer

How can I alter an existing Primary Key on SQL Azure?

I want to modify an existing primary key on a SQL Azure table. It currently has one column, and I want to add another. Now, on SQL Server 2008 this was a piece of cake, just did it in SSMS, poof. Done. This is how the PK looks like if I script it…
Magnus
  • 363
  • 1
  • 3
  • 6
26
votes
3 answers

How can I tell how many Cores SQL Server is actually using?

I have two servers running SQL Server. Server 1: SQL Server 2008 R2 Express (4 core) Server 2: SQL Server 2012 Developer Edition (8 core) As far as I am aware SQL Server 2008 R2 Express should only use one core. SQL Server 2012 Developer version…
Craig Edmonds
26
votes
2 answers

How do I map an IS-A relationship into a database?

Consider the following: entity User { autoincrement uid; string(20) name; int privilegeLevel; } entity DirectLoginUser { inherits User; string(20) username; string(16) passwordHash; } entity OpenIdUser { inherits User; …
Billy ONeal
  • 571
  • 2
  • 5
  • 7
26
votes
2 answers

How to partition an existing non-partitioned table

I have an existing table with data: dbo.Test (col1,col2,col3....) ON [PRIMARY] I need to change this table to be partitioned like this: dbo.Test(col1,col2,col3....) ON Ps_Date(Col2) How I can I achieve this without dropping and recreating the…
343
  • 263
  • 1
  • 3
  • 5
26
votes
5 answers

Identifying Unused Stored Procedures

This next year, I am helping an effort to clean several SQL Server environments. We have about 10,000 stored procedures and estimate that only about 1000 of them are used on a regular basis, and another 200 or so are used on a rare occasion,…
Question3CPO
  • 561
  • 1
  • 8
  • 13
26
votes
8 answers

Trying to find the last time that a value has changed

I have a table that has an ID, a value, and a date. There are many IDs, Values, and dates in this table. Records are inserted into this table periodically. The ID will always stay the same but occasionally the value will change. How can I write a…
SqlSandwiches
  • 1,607
  • 1
  • 15
  • 20
26
votes
4 answers

Whether or not to create separate tables for different product types?

I'm in the process of designing a database and I'm having second thoughts about my initial design decisions... Product types are as follows... Models, parts, replacement part kits and options. Option A (first design): I planned on having separate…
payling
  • 385
  • 1
  • 3
  • 7