Yoelji Yoelji - 2 months ago 18
SQL Question

SQL NEWBIE, LIKE CLAUSE

Hay guys i'm new to SQL could someone correct me this query ?!

USE GestionVolsDB
CREATE TABLE AVION
(AV int IDENTITY(100, 1) PRIMARY KEY,
AVMARQUE varchar(30) NOT NULL,
AVTYPE varchar(30) NOT NULL,
CAP int CHECK (CAP BETWEEN 100 AND 600),
LOC varchar(30)
)

CREATE TABLE PILOTE
(PIL int IDENTITY(1,1) PRIMARY KEY,
PILNOM varchar(30) NOT NULL,
ADR varchar(30)
)

CREATE TABLE VOLE
(
VOL varchar(5) PRIMARY KEY CHECK(VOL LIKE 'IT'[1,9][0,9][0,9]),
PIL int FOREIGN KEY REFERENCES PILOTE(PIL),
AV int FOREIGN KEY REFERENCES AVION(AV),
VD varchar(30) NOT NULL,
VA varchar(30) NOT NULL,
HD TIME CHECK (HD BETWEEN '00:00' AND '23:59'),
HA TIME CHECK (HA BETWEEN '00:00' AND '23:59')
)


VOL is a string with 5 characters that start with 'IT' and the rest are numbers first number is different then 0

PIL FOREIGN KEY FROM PILOTE TABLE

AV FOREIGN KEY FROM AVION TABLE

VD is the Departure city

VA is the Destination city

HD is the departure time

HV is the arriving time

Answer

It might be as simple as moving the quotes. Try:

LIKE 'IT[1,9][0,9][0,9]'