Last active
August 29, 2015 14:10
-
-
Save msh9/8e75f2d2c66d939f7701 to your computer and use it in GitHub Desktop.
Experimenting with SQL NULL vs. blank
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
USE [master] | |
GO | |
/****** Object: Database [Experiments] Script Date: 11/30/2014 4:39:05 PM ******/ | |
CREATE DATABASE [Experiments] | |
GO | |
ALTER DATABASE [Experiments] SET COMPATIBILITY_LEVEL = 110 | |
GO | |
ALTER DATABASE [Experiments] SET ANSI_NULL_DEFAULT OFF | |
GO | |
ALTER DATABASE [Experiments] SET ANSI_NULLS OFF | |
GO | |
ALTER DATABASE [Experiments] SET ANSI_PADDING OFF | |
GO | |
ALTER DATABASE [Experiments] SET ANSI_WARNINGS OFF | |
GO | |
ALTER DATABASE [Experiments] SET ARITHABORT OFF | |
GO | |
ALTER DATABASE [Experiments] SET AUTO_CLOSE OFF | |
GO | |
ALTER DATABASE [Experiments] SET AUTO_CREATE_STATISTICS ON | |
GO | |
ALTER DATABASE [Experiments] SET AUTO_SHRINK OFF | |
GO | |
ALTER DATABASE [Experiments] SET AUTO_UPDATE_STATISTICS ON | |
GO | |
ALTER DATABASE [Experiments] SET CURSOR_CLOSE_ON_COMMIT OFF | |
GO | |
ALTER DATABASE [Experiments] SET CURSOR_DEFAULT GLOBAL | |
GO | |
ALTER DATABASE [Experiments] SET CONCAT_NULL_YIELDS_NULL OFF | |
GO | |
ALTER DATABASE [Experiments] SET NUMERIC_ROUNDABORT OFF | |
GO | |
ALTER DATABASE [Experiments] SET QUOTED_IDENTIFIER OFF | |
GO | |
ALTER DATABASE [Experiments] SET RECURSIVE_TRIGGERS OFF | |
GO | |
ALTER DATABASE [Experiments] SET DISABLE_BROKER | |
GO | |
ALTER DATABASE [Experiments] SET AUTO_UPDATE_STATISTICS_ASYNC OFF | |
GO | |
ALTER DATABASE [Experiments] SET DATE_CORRELATION_OPTIMIZATION OFF | |
GO | |
ALTER DATABASE [Experiments] SET TRUSTWORTHY OFF | |
GO | |
ALTER DATABASE [Experiments] SET ALLOW_SNAPSHOT_ISOLATION OFF | |
GO | |
ALTER DATABASE [Experiments] SET PARAMETERIZATION SIMPLE | |
GO | |
ALTER DATABASE [Experiments] SET READ_COMMITTED_SNAPSHOT OFF | |
GO | |
ALTER DATABASE [Experiments] SET HONOR_BROKER_PRIORITY OFF | |
GO | |
ALTER DATABASE [Experiments] SET RECOVERY SIMPLE | |
GO | |
ALTER DATABASE [Experiments] SET MULTI_USER | |
GO | |
ALTER DATABASE [Experiments] SET PAGE_VERIFY CHECKSUM | |
GO | |
ALTER DATABASE [Experiments] SET DB_CHAINING OFF | |
GO | |
ALTER DATABASE [Experiments] SET FILESTREAM( NON_TRANSACTED_ACCESS = OFF ) | |
GO | |
ALTER DATABASE [Experiments] SET TARGET_RECOVERY_TIME = 0 SECONDS | |
GO | |
USE [Experiments] | |
GO | |
/****** Object: Table [dbo].[Table1] Script Date: 11/30/2014 4:39:05 PM ******/ | |
SET ANSI_NULLS ON | |
GO | |
SET QUOTED_IDENTIFIER ON | |
GO | |
CREATE TABLE [dbo].[Table1]( | |
[SomeField] [nchar](255) NULL, | |
[SomeId] [int] IDENTITY(1,1) NOT NULL | |
) ON [PRIMARY] | |
GO | |
/****** Object: Table [dbo].[Table2] Script Date: 11/30/2014 4:39:05 PM ******/ | |
SET ANSI_NULLS ON | |
GO | |
SET QUOTED_IDENTIFIER ON | |
GO | |
CREATE TABLE [dbo].[Table2]( | |
[OtherField] [nchar](255) NULL, | |
[OtherId] [int] IDENTITY(1,1) NOT NULL, | |
[Ref] [int] NULL | |
) ON [PRIMARY] | |
GO | |
/****** Object: Index [ClusteredIndex-20141130-163657] Script Date: 11/30/2014 4:39:05 PM ******/ | |
CREATE UNIQUE CLUSTERED INDEX [ClusteredIndex-20141130-163657] ON [dbo].[Table1] | |
( | |
[SomeId] ASC | |
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] | |
GO | |
/****** Object: Index [ClusteredIndex-20141130-163628] Script Date: 11/30/2014 4:39:05 PM ******/ | |
CREATE UNIQUE CLUSTERED INDEX [ClusteredIndex-20141130-163628] ON [dbo].[Table2] | |
( | |
[OtherId] ASC | |
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] | |
GO | |
SET ANSI_PADDING ON | |
GO | |
/****** Object: Index [NonClusteredIndex-20141130-163718] Script Date: 11/30/2014 4:39:05 PM ******/ | |
CREATE NONCLUSTERED INDEX [NonClusteredIndex-20141130-163718] ON [dbo].[Table2] | |
( | |
[OtherField] ASC | |
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] | |
GO | |
/****** Object: Index [NonClusteredIndex-20141130-163800] Script Date: 11/30/2014 4:39:05 PM ******/ | |
CREATE NONCLUSTERED INDEX [NonClusteredIndex-20141130-163800] ON [dbo].[Table2] | |
( | |
[Ref] ASC | |
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] | |
GO | |
USE [master] | |
GO | |
ALTER DATABASE [Experiments] SET READ_WRITE | |
GO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
USE Experiments; | |
SET NOCOUNT ON; | |
DECLARE @count int; | |
DECLARE @str nchar(255); | |
SET @count = 0; | |
WHILE @count < 15000 | |
BEGIN | |
INSERT INTO dbo.Table1(SomeField) | |
VALUES (NULL); | |
INSERT INTO dbo.Table2(OtherField | |
,Ref) | |
VALUES (NULL | |
,@@IDENTITY); | |
SET @count = @count + 1; | |
END | |
SET @count = 0; | |
WHILE @count < 15000 | |
BEGIN | |
SET @str = CONVERT(nchar(255), NEWID()); | |
INSERT INTO dbo.Table1(SomeField) | |
VALUES (@str); | |
INSERT INTO dbo.Table2(OtherField | |
,Ref) | |
VALUES (@str | |
,@@IDENTITY); | |
SET @count = @count + 1; | |
END | |
SET @count = 0; | |
WHILE @count < 15000 | |
BEGIN | |
SET @str = ''; | |
INSERT INTO dbo.Table1(SomeField) | |
VALUES (@str); | |
INSERT INTO dbo.Table2(OtherField | |
,Ref) | |
VALUES (@str | |
,@@IDENTITY); | |
SET @count = @count + 1; | |
END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
USE Experiments; | |
SET statistics time on; | |
SELECT count(*) | |
FROM dbo.Table1 AS tbl1 | |
LEFT OUTER JOIN dbo.Table2 AS tbl2 | |
ON tbl1.SomeField = tbl2.OtherField | |
WHERE tbl2.OtherField <> ''; | |
SELECT count(*) | |
FROM dbo.Table1 AS tbl1 | |
LEFT OUTER JOIN dbo.Table2 AS tbl2 | |
ON tbl1.SomeId = tbl2.Ref; | |
WHERE tbl2.OtherField <> ''; | |
SELECT count(*) | |
FROM dbo.Table1 AS tbl1 | |
LEFT OUTER JOIN dbo.Table2 AS tbl2 | |
ON tbl1.SomeId = tbl2.Ref; | |
SET statistics time off; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment