SQL Server Assingment PDF
SQL Server Assingment PDF
Ltd
[SQL, ASSIGNMENT]
[This Assignment has been designed keeping the level of training sessions in mind . Anybody
who wants to practice about queries and creating tables in MS SQL should go through this.]
SQL Assignment
Directions for questions 1-6. Each of the questions just gives a list of SQL data
types. In some cases the list may consist of what the book calls synonyms. In other
cases the types may not be synonyms, although they are related. For each question give
a brief statement of what kind of data can be stored in the list of types given.
These are all whole numbers. They vary in the how big a number they can hold.
4. MONEY, CURRENCY.
These are numeric types with decimal places for holding monetary values.
These can hold complete files, such as pictures or media. They are not of a fixed in size,
and the upper limit on their size is large.
These can hold date and time values. These are hybrid types. Although you think of
them as text type fields, it is possible to do arithmetic and numeric comparisons on
them.
7. Write an SQL command that will create a table named Friend with the following
fields and types: idno CHAR(3), name CHAR(24), address CHAR(24), birthday DATE,
waistsize INTEGER, giftvalue CURRENCY.
8. Write an SQL command that will create a table named Friend with the following
fields: idno, name, address, age, bankbalance. Each of these fields has characteristics
that would make a particular type appropriate for it. You need to choose the type and
size for the fields.
9. Write an SQL command that will put this name into a record in the Friend table:
'Road Runner'.
10. For the record created by the previous question, what values would be in the fields
other than the name field?
NULL
11. Write an SQL command that will insert a complete record into the Friend table with
these values for the respective fields: '123', 'Tasmanian Devil', 'Tasmania', #07/07/57#,
32, 29.99.
12. Write an SQL command that will insert a complete record into the Friend table with
these values for the respective fields: '456', 'Felix the Cat', 'Hollywood', NULL, NULL,
NULL.
13. Write an SQL command (with a query included) that will insert into Friend all of the
spno’s, names, and addresses from the salesperson table.
14. Write an SQL command (with a query included) that will insert into Friend all of the
custno’s, names, and addresses of customers where the state is equal to 'WA'.
15. Write an SQL command (with a query included) that will insert into Friend just the
custno’s of all of the customers where the state is equal to 'WA'.
16. Write an SQL command (with a query included) that will insert into Friend just the
spno’s and names of salespeople.
There aren’t as many fields in the Friend table as there are in the Salesperson table, so
it’s not possible to select all from Salesperson to insert into Friend. Plus, the respective
fields don't match anyway.
19. Write an SQL command that will update the giftvalue to 49.99 for all people in the
Friend table who are 21 and older.
UPDATE Friend
SET giftvalue = 49.99
WHERE age >= 21
20. Write an SQL command that will update the Friend table so that all waistsizes will
be 0.
UPDATE Friend
SET waistsize = 0
21. Write an SQL command that will add a city field to the Friend table. You can choose
its type and size.
22. Write an SQL command that will change the specifications of the name field in the
Friend table to CHAR(36).
23. Write an SQL command that will get rid of the city field from the Friend table.
24. Write an SQL command that will delete all records from the Friend table where the
giftvalue is over 100.
DELETE *
FROM Friend
WHERE giftvalue > 100
25. Write an SQL command that will drop the table Friend from a database, eliminating
it and all of its records.
The remaining questions refer to the salesdate field in the Carsale table.
26. A) What distinctive punctuation marks should be used to enclose date values in
queries? B) What different kinds of punctuation marks can be used inside date values
in order to separate month, day, and year?
A) number signs. B) Dashes and slashes are the correct separators for dates when you
want to enter values into a table or give a specific value for comparison in a WHERE
clause, for example. It is possible to print out dates with various punctuation marks
when doing formatting.
27. Write a query that will select all fields from the Carsale table where the salesdate is
after January 1st, 2006.
SELECT *
FROM Carsale
WHERE salesdate > #01/01/06#
28. Write the same query as for question 27, but use a different punctuation mark to
separate the parts of the date value.
SELECT *
FROM Carsale
WHERE salesdate > #01-01-06#
29. Write an SQL query that will select the salesdate field from the Carsale table
formatted as follows: month, day, and year in that order, numeric, separated by
slashes. You may assume that your computer is using U.S. default settings.
This answer is not supposed to be a trick. It merely points out the fact that the
format specified is the default for U.S. dates, so no separate FORMAT is needed in order
to achieve the desired results.
SELECT salesdate
FROM Carsale
30. Write an SQL query that will select the salesdate field from the Carsale table
formatted as follows: the full name of the day, a comma, the full name of the month,
the number of the day in the month, a comma, and a 4 digit year.
31. Write an SQL query that will select the salesdate field from the Carsale table
formatted as follows: 2 digit number of day in the month, 3 letter abbreviation of
month, 2 digit year. Spaces should be used as separators.
32. Write an SQL query that will select the salesdate field from the Carsale table
formatted as follows: 4 digit year, comma, 2 digit week of year, comma, 1 digit number
of day of the week.