473,609 Members | 2,263 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Create Table Conditional

3 New Member
I have this CREATE TABLE statement:

Expand|Select|Wrap|Line Numbers
  1. CREATE TABLE howto (
  2.     id INT IDENTITY(1,1) PRIMARY KEY,
  3.     title VARCHAR(100) UNIQUE NOT NULL,
  4.     url VARCHAR(20) UNIQUE NOT NULL,
  5.     order_on_homepage SMALLINT UNIQUE, --just put an order on this and if it's not null, then its on the homepage
  6.     CONSTRAINT CK_HOWTO_URL CHECK(url != ''),
  7.     CONSTRAINT CK_HOWTO_TITLE CHECK(title != '')
  8. );
  9. GO
I want order_on_homepa ge col to either have a SMALLINT value or a NULL value. However, if there is a SMALLINT value entered, I want those to be unique. In other words, I want to be able to add multiple NULL values in this col, but NOT multiple SMALLINT values. Any suggestions? A check? Thanks!
Mar 24 '08 #1
3 2057
ck9663
2,878 Recognized Expert Specialist
I have this CREATE TABLE statement:

Expand|Select|Wrap|Line Numbers
  1. CREATE TABLE howto (
  2.     id INT IDENTITY(1,1) PRIMARY KEY,
  3.     title VARCHAR(100) UNIQUE NOT NULL,
  4.     url VARCHAR(20) UNIQUE NOT NULL,
  5.     order_on_homepage SMALLINT UNIQUE, --just put an order on this and if it's not null, then its on the homepage
  6.     CONSTRAINT CK_HOWTO_URL CHECK(url != ''),
  7.     CONSTRAINT CK_HOWTO_TITLE CHECK(title != '')
  8. );
  9. GO
I want order_on_homepa ge col to either have a SMALLINT value or a NULL value. However, if there is a SMALLINT value entered, I want those to be unique. In other words, I want to be able to add multiple NULL values in this col, but NOT multiple SMALLINT values. Any suggestions? A check? Thanks!
I think a trigger would be better for this one.

-- CK
Mar 24 '08 #2
askohen
3 New Member
Any hints on how to do this? I created a test trigger, but not sure how to go forward,

Expand|Select|Wrap|Line Numbers
  1. CREATE TRIGGER test_howto
  2.     ON howto
  3.     FOR INSERT
  4.         AS Print('foo');
  5. GO
Mar 24 '08 #3
ck9663
2,878 Recognized Expert Specialist
I did not compile this:


Expand|Select|Wrap|Line Numbers
  1. CREATE TRIGGER TRG_HowtO
  2. ON HowTo
  3. FOR INSERT, UPDATE
  4. as
  5.    begin tran
  6.       if exists (select 1 from HowTo inner join inserted on HowTo.Order_on = inserted.Order_On)
  7.          rollback tran
  8.       else
  9.          commit tran
  10.  go
If the value of Order_On you inserted is NULL the exists function will still return false since you can not compare 2 NULLs.

-- CK
Mar 24 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2117
by: dawnunder | last post by:
eg. Someone fills out 3 fields. (There will be more but this is just to give you an idea) 1. Country? 2. State? 3. City I want this script to generate a web page and list the people by
2
2602
by: Terry | last post by:
I have cerated a Form, ExamsFrm, which is used to input details of exams taken at several Centres. It dosplays details from StudentTbl and has a SubForm which displays details from ExamsTble. I have incorporated some VB6 code as well as some Conditional Formatting. The code automatically updates CheckBoxes in the SubForm, depending on exam results, and the Conditional Formatting changes background colours, depending on CheckBox datum. ...
2
2606
by: Richard Hollenbeck | last post by:
I use a temporary table to assemble unrelated data for specific forms and reports. After each use of this table, I have a delete query which empties the table out for its next use. I have one field I want to populate with the record number as it appears in the form. That way I can use a comparison with Me.CurrentRecord to change the background color of the text boxes for the OnCurrent property. I'm doing this because I want the record...
4
1401
by: Steven | last post by:
Hi, I want to create an image that looks exactly the same as the things I see in my application. I have an application in which you can create some controls, drag them anywhere you like. Now I want to export these controls to an image. The image should reflect the position of the controls and the controls should look the same in the picture as they do on the screen.
61
9793
by: Paul Watt | last post by:
Hi, i've placed a table within a <div> to dispay some data. All is well in FF, but in MSIE the table starts inline with the bottom of the <div> to the left. I've set the css div to vertical align: top, but this hasn't made a differance. http://www.paulwatt.info/test/calendar.htm Thanks guys
0
1287
by: BrutalByte | last post by:
I have a report that I would like to apply conditonal formatting to by referencing another table's data. The "NSN" data table is a single column of NSNs. What string do I enter into the Conditional Formatting dialog box to reference the table's entire first column. All I want this to do is turn the referenced NSNs on the report red. Thanks in advance! Bryan
2
2755
by: mukesh | last post by:
Can we use expression in default value for a table field for example – IIf(Table-1.field-1=table-2 . field-1, table-1.field-2, 0) Interpretation – If field-1 of table -1 is like/equal to field-2 of table-2 then value of field-1 of table-1 will be the default value other wise 0 will be the default value Can I use this type of conditional default value if yes please tell me how. I tried to set this expression in default property of a...
2
1764
by: enywu | last post by:
Hi all, I have created a report in my access database through a query. The report has no problem, however now there is new request that they want this report to use the conditional formatting. Whereby the criteria is to be taken from a table. Is this possible to be done? For your info, I'm using Access 97. Any help will be much appreciated. Thank you.
1
2199
by: dstorms | last post by:
Hi folks, I am trying to set up my database to create a new record in one table when a new record is created in another. Since it is a one-to-one realtionship it certainly would be easier to put the data into one table. Originally it was one table, but I split the table to create conditional field-level security (read-only unless one box was unchecked). However I'm trying to fix one flaw in the whole scheme: When a user adds a new record in...
0
8519
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8208
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8386
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6050
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5506
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4068
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2526
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1644
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1378
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.