A. What are data types?
A data type in a programming language is a set of data with values having predefined characteristics. Examples of data types are: integer, floating point unit number, character, string, and pointer. Usually, a limited number of such data types come built into a language. The language usually specifies the range of values for a given data type, how the values are processed by the computer, and how they are stored.With object-oriented programming, a programmer can create new data types to meet application needs. Such an exercise as known as "data abstraction" and the result is a new class of data. Such a class can draw upon the "built-in" data types such as number integers and characters. For example, a class could be created that would abstract the characteristics of a purchase order. The purchase order data type would contain the more basic data types of numbers and characters and could also include other object defined by another class. The purchase order data type would have all of the inherent services that a programming language provided to its built-in data types.Languages that leave little room for programmers to define their own data types are said to be strongly-typed languages.
B. What role do they play in a database?
Data Types -- The Easiest Part of Database DesignDatabase design can be very complicated, and it truly is an art as opposed to a science; sometimes there are multiple correct ways to model the same data with pros and cons to each. I can understand that normalization can be tricky to comprehend and to implement, and that concepts like stored procedures and foreign keys and even indexes and constraints can take time to grasp.But -- what about Data Types? They are so basic, so simple, so fundamental; not only for database design, but for any sort of programming in general ... what excuse is there for not using correct data types for the columns in a table design?I see it time and time again in the SQLTeam forums -- "dates" that don't sort properly, "numbers" that don't add correctly, "boolean" columns containing 10 different values, invalid entries that somehow show up in "date" columns, and so on ... Of course, since we are rarely provided any DDL to review, it often takes dozens of posts going back and forth until we finally realize: "wait ... you aren't using a datetime data type to store these dates??? Arggh!!"In short, even a poorly designed database, with one giant "master" table with no normalization or logic anywhere in sight, should still at least use a Money data type to store currency values!Perhaps the confusion comes from Excel users, where data types are handled behind the scenes ... or maybe "old school" VB programmers used to using variant data types (or worse -- undeclared variables!) to store values... But when you design a table in any database, you are always explicitly stating the data types of the columns -- there's nothing hidden, or no option to ignore them. You must declare a data type when creating a column, so how can anyone justify using VARCHAR to store a date?
C. Enumerate 3 data types of DBMS and explain.
1. Fixed-length textThe char data type is used to store fixed-length text with up to 255 characters. Specifying the number of characters to store limits how big the column will be. Text values retrieved from a char column are padded with spaces, if necessary, to the size of the column. The char data type is not available from the Access designer.The following statement creates a table with a 10-character text column and a 255-character text column, both with Unicode compression:CREATE TABLE T1 (c1 char(10) WITH compression, c2 char WITH compression)2. Variable-length textThe varchar data type is used to store variable-length text with up to 255 characters.Text values retrieved from a varchar column are trimmed of any trailing spaces.The following statement creates a table with a 10-character text column and a 255-character text column, both with Unicode compression:CREATE TABLE T2 (c1 varchar(10) WITH compression, c2 varchar WITH compression)3. Text BLOBThe longchar data type is used to store variable-length text with an unspecified number of characters, limited only by the maximum size of JET database files (2 GB – about 1 billion uncompressed Unicode characters).Some software libraries are able to handle longchar columns as basic text columns, but others must use BLOB techniques for accessing their data. In particular, the ADO components so often used in Visual Basic, VBA and ASP applications can access longchar columns as basic text when using the JET 4.0 OLE-DB provider to access the database, but must use BLOB handling routines (GetChunk / AppendChunk) when using an ODBC connection.The following statement creates a table with two variable-length text BLOB columns, both with Unicode compression:
Thursday, July 2, 2009
Subscribe to:
Post Comments (Atom)

0 comments:
Post a Comment