For what DBMS, besides SQL Server, you would like to have exercises on the site?
SQL Exercises news letters, latest issue
#284 (2010-03-06)
Week news
§
As the important news can appear and between releases of news letters, I shall use this page for the publication of the information on all changes on the site.
The forum is not so suitable for this purpose since the message there "escapes" and can appear on previous page before it will lose a urgency.
So look in here if you wish to be well informed about last events on the site. The link to this page is in section of news at the main page below a subscription banner.
§
Has corrected a bug with checking the exercises:
18 (SELECT, rating stage) - formulation from Lady.
112 (SELECT, rating stage) - formulation from qwrqwr.
162 (SELECT, rating stage) - formulation from author.
17 (DML) - data from alex2008.
4 (SELECT, rating stage) - data from risp
§
Changes among leaders (solved exercises of third stage):
ANDREAS_PITER (A10055059) [BK] - g. Sankt-Peterburg, Rossiya
§
Statistics:
Number of subscribers - 3849
Number of rating's participants - 11371
Number of second-stage's participants - 2097
Number of third-stage's participants - 65
On the learning stage - 10944
Certified specialists in total - 426
Let us now see what happened with the definition of data. Below is a test script.
CREATE TABLE Test_char(
chr CHAR,
vchr VARCHAR
);
DELETE FROM Test_char;
INSERT INTO Test_char VALUES
('1','11111111112222222222333333333344444444445555555555');
INSERT INTO Test_char VALUES
('11111111112222222222333333333344444444445555555555', '1');
INSERT INTO Test_char VALUES
('2',CAST('111111111122222222223333333333' AS VARCHAR));
INSERT INTO Test_char VALUES
(CAST('111111111122222222223333333333' AS CHAR), '2');
INSERT INTO Test_char VALUES
('3', '3');
SELECT * FROM Test_char;
SQL Server 2008
chr vchr
3 3
So, only one row be inserted containing one character for each column. When you insert the remaining rows we get an error message:
String or binary data would be truncated.
The statement has been terminated.
which means that we should reduce the size of the string.
Although there is standard compliance, it seems to me that there is a contradiction that an explicit cast to the column type of the table does not work:
INSERT INTO Test_char VALUES
(CAST('111111111122222222223333333333' AS CHAR), '2');
It may be noted the sequence in behavior: VARCHAR is arbitrary size; the second row was not inserted due to an error exceeding the size (ERROR: value too long for type character(1)); explicit value conversion to the column type of the table works, cutting off the extra characters from the right.
MySQL 5.0
VARCHAR type is not supported without specifying the size of the string. CHAR corresponds CHAR (1) - as standard. Since the explicit conversion to CHAR leaves the length of the string without changing, then into the table, defined as
in the result, as in SQL Server, single row will be added:
chr vchr
3 3
Conclusions. In my humble opinion, none of these databases does not meet the standard behavior in those cases where the size of type is not specified. In my opinion, PostgreSQL is most consistent in the "particular implementation". In order to code portability, I would recommend that you always explicitly specify the size.