SQL Server:检查约束以检查客户是否超过18(SQL Server : check constraint to check customers are over 18)
我正在使用SQL Server Management Studio,并希望创建一个表,当日期输入到表中时,它会检查某人是否超过18。
我有:
CREATE TABLE tCustomer ( FirstName VARCHAR(20) NOT NULL, DateOfBirth DATE CHECK (DateOfBirth < GETDATE()) );
我知道目前这是错误的,因为它正在检查
DateOfBirth
是否小于当前时间。 但我似乎无法找到我想要的东西。如果它对于创建表太复杂,可能是某种触发器? 我真的不想使用存储过程。
非常感谢您的帮助。
干杯。
I am using SQL Server Management Studio and would like to create a table that when dates are entered in to the table, it checks that someone is over 18.
I have got as far as:
CREATE TABLE tCustomer ( FirstName VARCHAR(20) NOT NULL, DateOfBirth DATE CHECK (DateOfBirth < GETDATE()) );
I know this is currently wrong as all it is doing is checking that the
DateOfBirth
is less than the current time. But I can't quite seem to find what I am looking for.If it is too complex for create table, maybe some sort of trigger? I do not really want to use a stored procedure.
Your help would be appreciated.
Cheers.
原文:https://stackoverflow.com/questions/23041681
最满意答案
您可以将
:item_wrapper_tag
传递给您,如下所示:<%= t.input :arrives_in, :collection => [1,2,3,4], :as => :radio, :item_wrapper_tag => :li %>
您还可以传递
:collection_wrapper_tag
选项来更改所有无线电输入的包装,如下所示:<%= t.input :arrives_in, :collection => [1,2,3,4], :as => :radio, :item_wrapper_tag => :li, :collection_wrapper_tag => :ul %>
You can pass
:item_wrapper_tag
to you input like this:<%= t.input :arrives_in, :collection => [1,2,3,4], :as => :radio, :item_wrapper_tag => :li %>
You can also, pass the
:collection_wrapper_tag
option to change the wrapper of all radio inputs like this:<%= t.input :arrives_in, :collection => [1,2,3,4], :as => :radio, :item_wrapper_tag => :li, :collection_wrapper_tag => :ul %>
相关问答
更多-
我决定用nested_form gem代替cocoon gem,它也失败了。 问题在于主题及其要求将gem的js指令放在其自己的特殊清单中。 该主题的文档没有提到这一点。 它没有发生在我cocoon.js没有加载。 现在工作正常。 I decided to substitute the nested_form gem for the cocoon gem, and it also failed. The problem was with the theme and its requirement to pu ...
-
我找到了一个单选按钮的解决方案: view.slim: p Name = f.radio_button :call_time, 'first_name' p Surname = f.radio_button :call_time, 'last_name' p Nickname = f.radio_button :call_time, 'nickname' = f.button :submit I found a solution for radio buttons: view.slim: p Name ...
-
这可以通过模型less_form来实现。 看下面的代码: <%= simple_form_for :user, url: users_path do |f| %> <%= f.input :name, as: :string %> ... <% end %> url: users_path可以更改为您希望其发布到的操作。 在您的情况下, update_resolution_instance_path该操作将传递给它的参数并执行它需要做的任何事情。 我正在使用类似的东西来从字段中获取数据,然后向用户 ...
-
Ruby on Rails分类通过Simple_Form集合(Ruby on Rails Categorization Via Simple_Form collections)[2022-09-30]
查看simple_form的文档,它可以做你需要的: https : //github.com/plataformatec/simple_form#collections f.input :country_id, collection: @continents, as: :grouped_select, group_method: :countries 这是HTML选择提供的正常功能,所以您处于正确的轨道上! https://developer.mozilla.org/en-US/docs/Web/HTM ... -
错误在这一行: <%= f.input :category_id, collection: @categories, as: :grouped_select, label_method: :name, value_method: :id , input_html: { class: "form-control center" } %> 以下解决方案可能适用于您。 用以下任何解决方案替换该行: <%= f.association :category %> <%= f.input :category_id, ...
-
simple_form创建一个包含每个输入div的表单。 每个div包含一个标签和一个输入字段 所以你的CSS应该是这样的: .form-inline div { display: inline-block } simple_form creates a form containing a div for each input. Each div contains a label and an input field so your css should look like: .form-inline d ...
-
隐藏的字段是故意的,你可能不想删除它。 当没有选中复选框时,处理这种情况。 我认为simple_form最终会回到标准FormBuilder中相同的基本check_box逻辑。 这里是一些关于为什么复选框具有隐藏字段的文档。 从check_box文档中 : # The HTML specification says unchecked check boxes are not successful, and # thus web browsers do not send them. Unfortunately ...
-
试图将Simple_form gem的集合收音机的包装器转换为
- 元素(Trying to turn Simple_form gem's collection radio's wrapper into
- element)
[2023-03-14]您可以将:item_wrapper_tag传递给您,如下所示: <%= t.input :arrives_in, :collection => [1,2,3,4], :as => :radio, :item_wrapper_tag => :li %> 您还可以传递:collection_wrapper_tag选项来更改所有无线电输入的包装,如下所示: <%= t.input :arrives_in, :collection => [1,2,3,4], :a ... -
:prompt选项对此负责。 = simple_form_for :user do |f| = f.input :lang, collection: ["Ru", "En"], prompt: "Select language" :prompt option is responsible for that. = simple_form_for :user do |f| = f.input :lang, collection: ["Ru", "En"], prompt: "Select langua ...
-
看起来value_method接受lamba,所以像这样的东西可以工作: value_method: ->(image) { "#{image.id}-#{image.class}" } 更好的方法是使用自定义连接在所有类上定义image_key方法,然后执行以下操作: value_method: :image_key Looks like value_method accepts lamba's so something like this could work: value_method: ->(i ...