Day 7

Quiz

1:What is wrong with the following statement?
DELETE * FROM customer_demo

A1: This statement should not be using the '*'. In addition, the FROM keyword is optional. The correct syntax of this statement is
DELETE FROM customer_demo

Or

DELETE customer_demo

Remember that this would delete all the data in the table.

2:What is wrong with the following statement?
UPDATE customer_demo (
    'John', 'smith', 34)

A2: Answer: This statement mixes the UPDATE command with the INSERT command. To UPDATE values into the customer_demo table, you use the following syntax for an update:
UPDATE customer_demoSET Fname = 'John',
    Lname = 'smith'
    age = 34

And for an insert, the following syntax would be used:

INSERT INTO customer_demo
            (Fname, Lname, Age)
       Values('John', 'smith', 34)

3:What would happen if you executed the following statement?
DELETE * from customer_demo

A3: Nothing would be deleted because this is incorrect syntax. The * is not needed in the DELETE statement.
4:Will the following SQL statement work?
INSERT INTO customer_demo
SET VALUES = 758
WHERE ITEM = 'CAR'

A4: No, this statement would not work. The syntax is incorrect. The SET clause is not part of the INSERT statement.

Exercises

1:Create a table called customers_demo with the following columns: an identity column called cust_id; fname and lname as required fields; email, which is an optional email address; and cust_new to specify whether the customer is new. The cust_new column should default to 'Y' to specify that the customer is new to the company.
A1: The following code will create the table as described:
Create table customers_demo(
Cust_id int identity,
Fname varchar(30) not null,
Lname varchar(30) not null,
Email varchar(20) null,
Cust_new char(1) not null default 'Y')

2:Insert the following data into your table:
First Name Last NameEmailNew Customer?
JohnSmith[email protected]Y
JuliePinter N
BillBuckley[email protected]Y
SevenNine[email protected]N

A2: The following shows how to insert the specified data:
Insert customers_demo (fname, lname, email, cust_new)
    Values('John', 'Smith', '[email protected]')
Insert customers_demo (fname, lname, cust_new)
    Values('Julie', 'Pinter', 'N')
Insert customers_demo (fname, lname, email)
    Values('Bill', 'Buckley', '[email protected]')
Insert customers_demo (fname, lname, email, cust_new)
    Values('Seven', 'Nine', '[email protected]', 'N')

For email addresses that were not specified, I left them out, and let the server insert a NULL. When the new customer flag is 'Y', I left it out so that the server will insert the default value of 'Y'.

3:Try inserting values with the incorrect data types into the table. Note the errors and then insert values with correct data types into the table.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset