<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[SQL Server Tabelle mit Bedingungen]]></title><description><![CDATA[<p>Hallo Zusammen,</p>
<p>ich habe mal eine Frage. Geht das das man eine Spalte auf Null setzt, wenn irgendeine Bedingung erfüllt ist?<br />
Zb</p>
<pre><code>	CREATE TABLE [dbo].[Table]
(
	id int, -- wenn &lt; 0 dann Text = ' Wert kleiner 0'
	Text VARCHAR,
) 
</code></pre>
<p>Danke im Vorraus</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/351575/sql-server-tabelle-mit-bedingungen</link><generator>RSS for Node</generator><lastBuildDate>Thu, 08 Oct 2026 13:29:47 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/351575.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 14 Aug 2020 16:48:01 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to SQL Server Tabelle mit Bedingungen on Fri, 14 Aug 2020 16:48:01 GMT]]></title><description><![CDATA[<p>Hallo Zusammen,</p>
<p>ich habe mal eine Frage. Geht das das man eine Spalte auf Null setzt, wenn irgendeine Bedingung erfüllt ist?<br />
Zb</p>
<pre><code>	CREATE TABLE [dbo].[Table]
(
	id int, -- wenn &lt; 0 dann Text = ' Wert kleiner 0'
	Text VARCHAR,
) 
</code></pre>
<p>Danke im Vorraus</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2593954</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2593954</guid><dc:creator><![CDATA[Liz]]></dc:creator><pubDate>Fri, 14 Aug 2020 16:48:01 GMT</pubDate></item><item><title><![CDATA[Reply to SQL Server Tabelle mit Bedingungen on Fri, 14 Aug 2020 17:22:08 GMT]]></title><description><![CDATA[<p>Könntest du konkreter beschreiben was du vor hast?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2593956</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2593956</guid><dc:creator><![CDATA[5cript]]></dc:creator><pubDate>Fri, 14 Aug 2020 17:22:08 GMT</pubDate></item><item><title><![CDATA[Reply to SQL Server Tabelle mit Bedingungen on Fri, 14 Aug 2020 17:49:31 GMT]]></title><description><![CDATA[<p>Ich möchte Geräteanschlüsse verwalten. Abhängig vom Anschluss gibt es weiter Einstellungen. Hat ein Gerät zb einen seriellen Anschluss können dafür noch vereschiedene Dinge mit konfiguriert werden.<br />
Hat ein Gerät einen usb Anschluss gibt es diese Möglichkeit nicht.</p>
<p>Meine Idee war es jetzt das ich eine Tabelle mit den versch. Anschlussarten habe und eine weitere mit den Einstellungen.</p>
<p>An der Stelle habe ich mir überlegt wie ich sicher sein kann das nicht usb und com eingetragen wird.<br />
Ich weiß gar nicht ob das irgendwie Sinn macht, aber da dachte ich halt wenn<br />
usb -&gt; com = null</p>
<p>Edit: ich hatte bisher nicht wirklich mit Datenbanke zu tun</p>
<p>Edit2 So sieht jetzt mal grob die Tabellenstuktur aus</p>
<pre><code>---------------	---------------
Anschlusart		Anschlus
--------------- -------------
1 | usb			1| usb1 
2 | com		        1| usb2       ....
3 | tcp
 
 
----------
Settings
---------
1| setting1 -- gehört zu usb1</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2593957</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2593957</guid><dc:creator><![CDATA[Liz]]></dc:creator><pubDate>Fri, 14 Aug 2020 17:49:31 GMT</pubDate></item><item><title><![CDATA[Reply to SQL Server Tabelle mit Bedingungen on Fri, 14 Aug 2020 17:48:20 GMT]]></title><description><![CDATA[<p>Habe auch gerade solch ein Problem im Studium. Bin gespannt auf das Ergebnis! Thx für jede Hilfe!! <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f60a.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--smiling_face_with_smiling_eyes"
      title=":smiling_face_with_smiling_eyes:"
      alt="😊"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2593963</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2593963</guid><dc:creator><![CDATA[codegod70]]></dc:creator><pubDate>Fri, 14 Aug 2020 17:48:20 GMT</pubDate></item><item><title><![CDATA[Reply to SQL Server Tabelle mit Bedingungen on Fri, 14 Aug 2020 18:45:47 GMT]]></title><description><![CDATA[<p>Wenn du das wirklich machen willst, dann so mit SQL CONSTRAINT CHECK<br />
Ich bin kein SQL Experte, aber so müsste man es machen, wenn das Einfügen (oder Ändern...) von Einträgen consistency checks erfüllen müssen.</p>
<p>Das hier macht dass ein Device mit Spalte usb und Spalte com, eins von beiden haben muss, aber nicht beide.<br />
könnte für dein Fall etwas komplizierter werden.</p>
<pre><code class="language-sql">CREATE TABLE Device
(
    /*...*/
    CONSTRAINT myConstraint CHECK 
    ((com IS NULL AND usb IS NOT NULL) OR
    (com IS NOT NULL AND usb IS NULL))
)
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2593972</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2593972</guid><dc:creator><![CDATA[5cript]]></dc:creator><pubDate>Fri, 14 Aug 2020 18:45:47 GMT</pubDate></item><item><title><![CDATA[Reply to SQL Server Tabelle mit Bedingungen on Fri, 14 Aug 2020 18:53:22 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/21447">@5cript</a> Hey das sieht ja schon gut aus. Danke :). An welche Stelle pack ich das dann, hinter die Spaltendefinition?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2593973</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2593973</guid><dc:creator><![CDATA[Liz]]></dc:creator><pubDate>Fri, 14 Aug 2020 18:53:22 GMT</pubDate></item><item><title><![CDATA[Reply to SQL Server Tabelle mit Bedingungen on Fri, 14 Aug 2020 18:55:38 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/35905">@Liz</a></p>
<p>Ich würds persönlich ganz hinter alle Spaltendefinitionen schreiben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2593974</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2593974</guid><dc:creator><![CDATA[5cript]]></dc:creator><pubDate>Fri, 14 Aug 2020 18:55:38 GMT</pubDate></item><item><title><![CDATA[Reply to SQL Server Tabelle mit Bedingungen on Fri, 14 Aug 2020 18:58:21 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/21447">@5cript</a> Top Danke</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2593975</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2593975</guid><dc:creator><![CDATA[Liz]]></dc:creator><pubDate>Fri, 14 Aug 2020 18:58:21 GMT</pubDate></item><item><title><![CDATA[Reply to SQL Server Tabelle mit Bedingungen on Fri, 14 Aug 2020 21:13:24 GMT]]></title><description><![CDATA[<p>usb1 / usb2 ist doch redundant.<br />
Ich würde das bisher gesagte so auf drei Tabellen aufteilen:</p>
<p>Tabelle Anschlussart:</p>
<pre><code>Nr   Beschreibung
1    USB
2    COM
3    TCP
...
</code></pre>
<p>Tabelle Anschluss:</p>
<pre><code>Anschlussart  Nr
1             1
1             2
1             3
2             1
2             2
...
</code></pre>
<p>Tabelle Settings:</p>
<pre><code>Anschlussart Nr Settings
1            1  Settings für USB1
1            2  Settings für USB2
2            1  Settings für COM1
...
</code></pre>
<p>Dann benötigt man bis hierher erst mal gar keine nullfähigen Spalten.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2593976</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2593976</guid><dc:creator><![CDATA[Belli]]></dc:creator><pubDate>Fri, 14 Aug 2020 21:13:24 GMT</pubDate></item><item><title><![CDATA[Reply to SQL Server Tabelle mit Bedingungen on Wed, 26 Aug 2020 13:00:50 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/22666">@Belli</a> auch vielen Dank für deine Antwort. Habs jetzt so ähnlich auch umgesetzt</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2594251</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2594251</guid><dc:creator><![CDATA[Liz]]></dc:creator><pubDate>Wed, 26 Aug 2020 13:00:50 GMT</pubDate></item><item><title><![CDATA[Reply to SQL Server Tabelle mit Bedingungen on Wed, 26 Aug 2020 16:08:09 GMT]]></title><description><![CDATA[<p>So habe ichs jetzt umgesetzt:</p>
<p>Tabelle Anschluss (ID, Beschreibung)</p>
<pre><code>ID Beschreibung
1  usb
2  com
3  com
...
</code></pre>
<p>Tabelle com (fk_anschluss references Anschluss (ID))</p>
<pre><code>ID  Setting1   Setting2 ...
2  'Setting1' 'Setting2' ...
...
</code></pre>
<p>Das selbe für die Anderen Anschlüsse auch. Da ich so ja nicht verhindern kann  das in der com Tabelle zb was mit der ID 1 eingetragen wird. Hab ich mir ein Constraint check zusammengebaut wo ich prüfe ob <strong>ID</strong> UND <strong>Bezeichnung</strong> in der Anschlusstablelle existieren.</p>
<pre><code>create function fnCheckID (@Input varchar(45), @id int)

returns bit

AS
begin
  declare @Val varchar(45)
  declare @RetVal bit

  select @Val = (select type from Connection c
	where c.idConnection = @id and
	c.type = @Input)

if (@Val is not null)
	set @RetVal = 1
else 
  set @RetVal = 0

return @RetVal
  end
</code></pre>
<p>Ist vielleicht etwas umständlich, aber funktioniert soweit.</p>
<p>ABER:<br />
Wird die Bezeichnung in der Tabelle Anschlussart jetzt verändert, dann passts natürlich nicht mehr.<br />
Gibt es die Möglichkeit so ein Constraint in beide Richtungen zu machen? Vielleicht weiß ja einer von euch was.</p>
<p>lg Liz</p>
<p><strong>Edit</strong><br />
Ich glaube ich machs mir da viel zu komlpiziert. Nehme ich die Beschreibung auch noch als Fremdschlüssel in der com Tabelle auf, dann umgehe ich das Problem der inkosistenz. Richtig?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2594255</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2594255</guid><dc:creator><![CDATA[Liz]]></dc:creator><pubDate>Wed, 26 Aug 2020 16:08:09 GMT</pubDate></item></channel></rss>