Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Standard view
Full view
of .
Look up keyword
Like this
0 of .
Results for:
No results containing your search query
P. 1
SQL- Useful Questions & Answers

SQL- Useful Questions & Answers

Ratings: (0)|Views: 417|Likes:
Published by Kapil Samadhiya
Useful document for all Testing & DB Professionals.

Specially for Testers who are working/learning DataBase / RDBMS Testing.

Please go through it and feel free to ask in case of any doubt.

Good Luck....
Kapil Samadhiya
Useful document for all Testing & DB Professionals.

Specially for Testers who are working/learning DataBase / RDBMS Testing.

Please go through it and feel free to ask in case of any doubt.

Good Luck....
Kapil Samadhiya

More info:

Published by: Kapil Samadhiya on May 24, 2010
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less





SQL Basics
 primary key 
is a column or set of columns that uniquely identifies the rest of the data in any givenrowA
foreign key 
is a column in a table where that column is a primary key of another table, whichmeans that any data in a foreign key column must have corresponding data in theother table where that column is the primary key
Data inconsistency:
A Data field with same name but info does not match. (Occurs when DataRedundancy exists)
Data dependency:
When application depends on Data structure and has no flexibility.
Data Redundancy:
When a data item exists in several files (duplication) (Eliminated if usingNormalized data structure)
Data Independence:
Data structures are defined separately from application programs.
Two-dimensional tables of data values = Table
Values cannot be broken down any further.
Values for attributes are drawn from a domain. Atomic set of attributes.Ex: Date, City, etc.
Candidate Key:
Several keys that act as a subject for primary key.
Concatenated key:
Combination of attributes (from candidate keys) that forms the primary key.
Alternate Keys:
Candidate keys not chosen to be part of primary key.
Entity integrity:
No part of the primary key can be missing. "NOT NULL"
Referential Integrity:
A foreign key must have applicable primary key in other table.
Data Warehousing The Fundamentals
Single, complete and consistent store of data obtained from various sources. It is usually madeof relational databases. It consists of:- A set of programs that extract data from an operational environment.- A database that maintains data warehouse data,- Systems that provide data to users.
The main function of a data warehouse is to give end-users faster, easier, and more directaccess to corporate data.
Data Warehouses are offline systems. Their information is not live and it is notcontinuously updated.- One of the big advantages of a warehouse implementation is its ability to store historical data.
Codd Rules
In 1985 Codd proposed an informal set of twelve rules by which a database could be evaluated to seehow "relational" it is. Very few commercial databases exist which meet or satisfy all twelve rules.
The 12 rules are based on the following foundation rule.
Rule 0:
For any system that is advertised as, or claims to be, a relational database management system, thatsystem must be able to manage databases entirely through its relational capabilities. In other words,the DBMS should not have to rely on non-relational methods in order to manage its data. The othertwelve rules are all implied in Rule 0, but it is easier to check for the other twelve individually than forthis general rule.
Rule 1:
The information ruleAll information in a relational database is represented explicitly at the logical level and in exactly oneway - by values in tables. This includes data about the database itself. Data about the database itself is kept in a data dictionary.
Rule 2:
The guaranteed access rule.Each and every datum (atomic value) in a relational database is guaranteed to be logically accessibleby resorting to a combination of table name, primary key value, and column value. If a databaseconforms to rule 2, every atomic value should be easily retrievable. An atomic value is the smallestunit of value in a relational database. In a relational database, an atomic value can always be
retrieved if you know the column or attribute name, the table it is stored in, and the primary key'svalue.
Rule 3:
Systematic treatment of null valuesNull values (distinct from the empty character string or a string of blank characters and distinct fromzero or any other number) are supported in a fully relational DBMS for representing missinginformation in a systematic way, independent of data type. A null value can mean that data is notthere is not known, or is irrelevant. The null value represents empty database fields. There is novalue for that field. It is different from zero or blank. A primary field should never have and emptyfield. This protects the integrity of the database.
Rule 4:
Query languageThe database description is represented at the logical level in the same way as ordinary data, so thatauthorized users can apply the same relational language to its interrogation as they apply to theregular data. In a relational database the same query language is used on the data dictionary as isused on the application database.
Rule 5:
The comprehensive data sub language rule A relational system may support severallanguages and various modes of terminal use (for example, the fill-in-the-blanks mode). However,there must be one language whose statements are expressible, per some well defined syntax, ascharacter strings and that is comprehensive in supporting all the following items: Data definition,view definition, data manipulation, integrity constraints, authorization, transaction boundaries.There are often many different ways of interacting with the database, for example QBE (Query ByExample) or SQL (for more sophisticated queries)
Rule 6:
View updating ruleAll views that are theoretically updateable are also updateable by the system. A view is a "virtualtable" in a database. With a relational DBMS, any change that a user makes to a view should ideallyalso be made in the base table from which the view is derived.
Rule 7:
High-level insert, update and deleteThe capability of handling a base relation or a derived relation as a single operand applies not only tothe retrieval of data but also to the insertion, update and deletion of data. This means that onecommand in a relational database should be able to carry out an operation on one or more rows ineither a base relation or a view.
Rule 8:
Logical integrityApplication programs and terminal activities remain logically unimpaired whenever any changes aremade in either storage representation or access methods.Ex: moving tables to different disk drives, changing the order of rows in the table, reorganizingdatabase files. In a relational environment the DBMS decides how to access a piece of data.
Rule 9:
Data independenceApplication programs and terminal activities remain logically unimpaired when information-preservingchanges of any kind that theoretically permit unimpairement are made to the base tables. Relationaltables may have to be expanded or restructured. New tables may also have to be added to thedatabase. Expansion of a table may involve adding columns to existing tables. The addition of a newcolumn to a table in a relational database should not affect programs that use that table.
Rule 10:
Integrity constraintsIntegrity constraints specific to a particular relational database must be definable in the relational datasublanguage and stored in the catalog, not in the application programs. No data should be stored in arelational database that has not been defined beforehand. Integrity controls must exist to protect theconsistency of the database from unauthorized users. Two integrity constraints exist: Entity integrityand referential integrity. Entity integrity states that no part of the primary key can be missing. Thekey is said to be "not null". Referential integrity relates to the use of foreign keys. A foreign key is anattribute or group of attributes that matches the primary key of another table. If a table has a foreignkey to represent a relationship, then the related table must have a matching primary key.
Rule 11:
Extension of rule 8.A relational DBMS has distribution independence. Distribution independence means that applicationprograms and terminal activities remain unaffected when data distribution is first introduced, whendata is redistributed.Rule 8 requires that data should remain unaffected by the ways in which it is stored. Rule 11 requiresthat independence should still hold when data is distributed across different locations.
Rule 12:
Integrity constraints in the high-level language of the RDBMS. If a relational system has alow-level (single-record-at-a-time) language, that low-level language cannot be used to subvert orbypass the integrity rules and constraints expressed in the higher-level relational language (multiple-records-at-a-time). This rule guarantees the integrity constraints contained in the high-level languageof the DBMS. In some case, you want to use a one-record-at-a-time procedure. A procedurallanguage such as C, Cobol, or Fortran is used for this. These procedural languages cannot bypass theDBMS.
Data Handling Techniques, DML, DDL, DCL
DML (Data Manipulation Language)[
]DDL (Data Definition Language)[
]DCL (Data Control Language)[
SELECT Statement examples:
Eg:SELECT discount, stor_id AS bookstore, discountFROM discountsEg:OTHER alias examples:SELECT discount, stor_id bookstore, discountFROM discountsEg:SELECT discount, bookstore = stor_id, discountFROM discountsEg: With Text:SELECT 'The answer is:' discount, stor_id, discountFROM discountsEg: With Math:SELECT discount, stor_id, discount, discount*1.75 AS 'UK VAT'FROM discountsEg: Without repeat:SELECT DISTINCT stateFROM storesEg: The WHERE clause:SELECT titleFROM titlesWHERE title_id='MC2222'Eg: Using the BETWEEN Statement (BETWEEN is inclusive!):SELECT title_id, qtyFROM sales

Activity (42)

You've already reviewed this. Edit your review.
CharanKumar liked this
naresh1041 liked this
1 thousand reads
1 hundred reads
johntandra liked this
krisnaresh liked this
rajesh787 liked this
Amysmom2 liked this
pankajk4 liked this
pankajk4 liked this

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->