2

I want to add a column S_order_no in a table Sales_order with a constraint that the first letter must start with 0. So that if we try to write the first letter other than 0 it throws an error. Is it possible?. If yes please explain with an example.

sales_order table

wchiquito
  • 16,177
  • 2
  • 34
  • 45
Tavish Barua
  • 41
  • 1
  • 4

2 Answers2

0
CREATE TABLE Sales_order(
    S_order_no varchar(6) primary key check(S_order_no Like 'O%'),
    S_order_date Date,
   
);
blackgreen
  • 34,072
  • 23
  • 111
  • 129
  • 2
    Please don't post only code as answer, but also provide an explanation what your code does and how it solves the problem of the question. Answers with an explanation are usually more helpful and of better quality, and are more likely to attract upvotes. – Mark Rotteveel Jul 26 '20 at 09:06
-1

You can try:

MySQL / SQL Server / Oracle / MS Access:

CREATE TABLE Sales_order(
    S_order_no varchar(6) primary key,
    S_order_date Date,
    CONSTRAINT CHK_order_no CHECK (left(S_order_no, 1) = '0')
);
Whoiskp
  • 444
  • 4
  • 7