Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This can be a good starting point to do what you want :</p> <p><a href="http://sqlfiddle.com/#!6/61cc6/20" rel="nofollow">SQL Fiddle</a></p> <p><strong>MS SQL Server 2012 Schema Setup</strong>:</p> <pre><code>CREATE TABLE Content ( [ContentId] INT NOT NULL, [Title] NVARCHAR (50) Not NULL, CONSTRAINT [PK_Content] PRIMARY KEY CLUSTERED ([ContentId] ASC) ); </code></pre> <p><strong>Query 1</strong>:</p> <pre><code>DECLARE @key VARCHAR(5), @i int DECLARE @query VARCHAR(120) SET @i = 1 WHILE @i &gt; 0 BEGIN SET @key = (SELECT ABS(Checksum(NewID()) % 89999) + 10000) SET @i = (SELECT count(*) FROM Content WHERE ContentId = @key) END SET @query = 'INSERT INTO Content (ContentId,Title) VALUES ('+@key+',''Whatever'+@key+''');' exec(@query) </code></pre> <p><strong><a href="http://sqlfiddle.com/#!6/61cc6/20/0" rel="nofollow">Results</a></strong>:</p> <p><strong>Query 2</strong>:</p> <pre><code>DECLARE @key VARCHAR(5), @i int DECLARE @query VARCHAR(120) SET @i = 1 WHILE @i &gt; 0 BEGIN SET @key = (SELECT ABS(Checksum(NewID()) % 89999) + 10000) SET @i = (SELECT count(*) FROM Content WHERE ContentId = @key) END SET @query = 'INSERT INTO Content (ContentId,Title) VALUES ('+@key+',''Whatever'+@key+''');' exec(@query) </code></pre> <p><strong><a href="http://sqlfiddle.com/#!6/61cc6/20/1" rel="nofollow">Results</a></strong>:</p> <p><strong>Query 3</strong>:</p> <pre><code>select * from Content </code></pre> <p><strong><a href="http://sqlfiddle.com/#!6/61cc6/20/2" rel="nofollow">Results</a></strong>:</p> <pre><code>| CONTENTID | TITLE | |-----------|---------------| | 22537 | Whatever22537 | | 66089 | Whatever66089 | </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload