skip to main |
skip to sidebar
Chapter 3. SQL Basics
- SQL is based on the relational model but doesn't implement it faithfully
- SQL is a free form language whose statement can :
- be in uppercase or lowercase.
- start in any column.
- an intrenative sql statement ends with a semicolon.
- an identifier is a name that lets you refer to an object(schema,database ,column,key).
- database name must be unique.
- table and view names must be unique.
- column ,key,index and constraint names must be unique .
- you can give the same name of column in diferent tables.
- here's some more advice for choosing your identifier names :
- use a lowercase letters.
- names_with_underscore are easier to read than namewithunderscore.
- if you are worried that your identifier might be a reserved word in some other SQL dialect just add an underscore (for example element_).
- use the statement create table and alter table to defineor change a column data type.
- database designers choose data type carefully.
- use charactere string data types to represent text ,a character string or just string
- its lenght can be fixed or varying.
- it's a case sensitive('A' come before 'a').
- in sql statement ,a string is surrouded by a single quotes.
- charactere string types :
- CHARACTERE(lenght) represent a fixed numbers of characteres(CHARACTERE and CHAR are synonyms) .
- CHARACTERE VARYING (lenght) the DMBS store the string as is and doesn't pad itwith spaces.
- NATINAL CHARACTERE:this data type is the some as charactere except that is hold unicode charactere (NCHAR).
- CLOB:the caractere large object type is intended for use in library databases that holds vast among of text.
- NATIONAL CLOB:is like CLOB execpt that is hold unicode characteres.
- BINARY LARGE OBJECT TYPE: BLOB are used to store large amounts of multimedia data(graphic,audio,video,photo...),scientific data.
- BLOB can't be used as keys or indexes
- BLOB can be compared for only equality (=)or inequality(<>).
- you can't used BLOB with DISTINCT or GROUP BY or ORDER BY clauses.
- DMBS BLOB types :sql server binary,varbinary,image.
- EXACT NUMERIC TYPE :to represent exact numerical value
- it can be negative or positive number.
- it's an integer or a decimal number.
- it has a fixed precision and scale.
- exact numeric type:
- NUMERIC :represent a decimal number ,storedin a column defined as NUMERIC(precision,scale).
- DECIMAL is similaire to numeric ,the diference is that decimal has a precision greater that numeric.
- integer
- smallint: is similaire to integer but it might hold a smaller range of values.
- bigint
- sql server exact numeric type :bigint,iny ,smallint,tinyint,decimal,numeric.
- APPROXIMATE NUMERIC TYPES:an approximate numeric type has thesecharactéristics:
- it can a negative or positive number
- it typically is used to represent the very small or very large quantities common intechnical ,scientific calculations.
- approximate numeric type:
- FLOAT:represent a floating point number,stored in a column defined as FLOAT(precision).
- REAL:is similaire to float exceptthat the DMBS defines the precision(real takes no argument).
- DOUBLE PRECISION
- BOOLEAN TYPE:have three values :true ,false,unknown.
- DATA TIME TYPE:use the data time type to represent data and time.
- you can compare two datatimevalues.
- sql server:datetime,smalldatetime,rowversion.
- OTHER DATA TYPE:the sql standard define other data type than the one covered in the preceding section.
- you can find data type for:network and internet @,links to files stored outside the databases.
- sql server:uniqueidentifier,identity.
- NULLS :when your data is imcomplete you can use a null to represent a missing or unknown values.
- NULLs are eliminated by splitting the original tableinto one-to-one relationship.
Aucun commentaire:
Enregistrer un commentaire