Question: I have a scenario that i need to extract remark from the database table and display it, in such a way that

* if length of remark is greater than 20 then
* Display the first 18 characters and attach `...` with the remark

For this i am using the following code

```
 Dim SQL As String="Select * from MyTable where id='2'"
 Dim cmd As New OdbcCommand(SQL,con)
 con.Open()
 Dim reader As OdbcDatareader= cmd.ExecuteNonQuery()
 If reader.HasRows then
    Dim content As String = reader.Item("remark")
    If Len(content) > 20 Then
       content = content.Substring(0, 20) & ".."
    End If
    ' read remaining rows
 End If

```

All works fine, my doubt is that can i use this operation in query itself?

```
    If Len(content) > 20 Then
       content = content.Substring(0, 20) & ".."
    End If

```

Any help will be appreciated, thank you

Answer: 
Since you want to delete all booking rows when a package is deleted, the package table must be the primary table and the booking table must reference the package table. Remove the foreign key constraint from the table and add the following to the bookings table:

```
CONSTRAINT booking_packageFK
    FOREIGN KEY (packageCode)
    REFERENCES package (packageCode)
    ON DELETE CASCADE 

```

You should also remove the UNIQUE constraint from the packageCode on the booking table.
I don't think you have your foreign key relationship set up correctly even between Customer and Booking.
In your `Create Table customer` following tells the server that CustomerId is the Primary Key in customer table:

```
CONSTRAINT customerPK
        PRIMARY KEY (customerID)

```

In your `Create Table booking` following tells the server that CustomerId is the Primary Key as well as a Foreign Key that references customer:

```
 CONSTRAINT bookingPK
        PRIMARY KEY (customerID),

    CONSTRAINT bookingFK
        FOREIGN KEY (customerID)
        REFERENCES customer (customerID)
        ON DELETE CASCADE

```

Similarly in your package table you have set packageCode as both primary and foreign key.

What I think you need is:

1. `CustomerId` in `Customer` table should be the primary key
2. There should be a `BookingId` and a `CustomerId` in the `Booking` table. `BookingId` will be the primary key and `CustomerId` will be the foreign key that references `Customer`.
3. There should be a `BookingId` in the `Package` table. It will be a foreign key that references `Booking`.