Tagged Questions
26
votes
6answers
2k views
WHERE Clause vs ON when using JOIN
Assuming that I have the following T-SQL code:
SELECT * FROM Foo f
INNER JOIN Bar b ON b.BarId = f.BarId;
WHERE b.IsApproved = 1;
The following one also returns the same set of rows:
SELECT * FROM ...
21
votes
2answers
13k views
In SQL Server 2008 R2 script data missing on Script Wizard
In my SQL Server 2008 R2
Script Option Screen of Script Wizard under section Table/View Options Look I find Script Data row and want to turn the option to True but I fail.
I don't find any script ...
19
votes
2answers
422 views
PHP & SQL Server - field names truncated
Here is the relevant code:
function connect(){
// DB credentials and info defined here....
$connection = odbc_connect("DRIVER={SQL Server Native Client 11.0}; Server=$server; Database=$db;", ...
17
votes
5answers
4k views
SQLCLR using the wrong version of the .NET Framework
During a recent restart of our development server the SQL Server started using .NET 4.0 for the SQLCLR. This means that nothing using the CLR in SQL works, or at least that's my understanding by ...
14
votes
3answers
19k views
SQL Server 2008: How to query all databases sizes?
I have MS SQL 2008 R2, 500 databases.
What is the most efficient, easiest and 'modern' way to query all databases sizes.
The output should have columns:
DatabaseName
DataFilesSize
LogFilesSize
14
votes
4answers
2k views
What do you do to make sure a new index does not slow down queries?
When we add or remove a new index to speed up something, we may end up slowing down something else.
To protect against such cases, after creating a new index I am doing the following steps:
start ...
13
votes
7answers
7k views
Fastest way to find string by substring in SQL?
I have huge table with 2 columns: Id and Title. Id is bigint and I'm free to choose type of Title column: varchar, char, text, whatever. Column Title contains random text strings like "abcdefg", "q", ...
11
votes
6answers
3k views
How to return default value from SQL query
Is there any easy way to return single scalar or default value if query doesn't return any row?
At this moment I have something like this code example:
IF (EXISTS (SELECT * FROM Users WHERE Id = ...
11
votes
5answers
18k views
Upgrading from SQL Server 2008 R2 Express to SQL Server 2008 R2 Enterprise
When I tried upgrading from SQL Server 2008 R2 Express to SQL Server 2008 R2 Enterprise, it passed all tests and then it failed at step "Select features", saying the following error:
There are no ...
11
votes
1answer
596 views
Migrating from MySQL to SQL Server, issues with constraints
I created a web app that uses a MySQL database, but I have to migrate the database to Microsoft SQL Server 2008 R2 and I'm using the SQL Server Migration Assistant (SSMA).
I'm getting errors in my ...
10
votes
2answers
31k views
CREATE TABLE IF NOT EXISTS equivalent in SQL Server [duplicate]
Possible Duplicate:
SQL Server: Check if table exists
CREATE TABLE IF NOT EXISTS works on mysql but fails with SQL Server 2008 R2.
What is the equivalent syntax?
10
votes
2answers
1k views
Is this a bug in MERGE, failing to implement FOREIGN KEY properly?
I am using the following tables to implement subtypes, which is a very common approach:
CREATE TABLE dbo.Vehicles(
ID INT NOT NULL,
[Type] VARCHAR(5) NOT NULL,
CONSTRAINT Vehicles_PK ...
10
votes
1answer
163 views
Does SQL Server support IS DISTINCT FROM clause?
Does SQL Server support IS DISTINCT FROM statement which is SQL:1999 standard? E.g. the query
SELECT * FROM Bugs WHERE assigned_to IS NULL OR assigned_to <> 1;
can be rewritten using IS ...
9
votes
6answers
34k views
how to check if table exist and if it doesnt exist create table in sql server 2008
I am writing a Stored procedure in sql server 2008
I need to check if a table exist in the DB, if it doesnt then ineed to create it.
How do i do it?
Thanks
Prady
9
votes
2answers
5k views
Return total records from SQL Server when using ROW_NUMBER
I would like to return the total number of records in the database so I can set up pagination. How do I return the total number of records in the DB when using the following paging method in SQL ...