X


Introduction to SQL







SQL Data Definition







SQL standard - built-in data types,






Additional Information :


  1. Each type may include a special value called the null value. A null value indicates an absent value that may exist but be unknown or that may not exist at all.


  2. The char data type stores fixed length strings. Consider, for example, an attribute A of type char(10). If we store a string "Avi" in this attribute, 7 spaces are appended to the string to make it 10 characters long. In contrast, if attribute B were of type varchar(10), and we store "Avi" in attribute B, no spaces would be added.


  3. When comparing two values of type char, if they are of different lengths extra spaces are automatically added to the shorter one to make them the same size, before comparison.


  4. When comparing a char type with a varchar type, one may expect extra spaces to be added to the varchar type to make the lengths equal, before comparison; however, this may or may not be done, depending on the database system. As a result, even if the same value “Avi ” is stored in the attributes A and B above, a comparison A = B may return false. We recommend you always use the varchar type instead of the char type to avoid these problems.


  5. In some databases, SQL also provides the nvarchar type to store multilingual data using the Unicode representation






Basic Schema Definition





Basic Structure of SQL Queries






Q. Find the names of all instructors.


name
Pranav
Abhishek
Satish
Ravi
Ajeet


Q. Find the names of all departments in which instructors are working by removing duplicates.


Dept_names
IT
EXTC
CMPN
IT
ETRX




Q. Find the names of all departments in which instructors are working without removing duplicates.


Dept_names
IT
EXTC
CMPN
IT
ETRX




Q. The select clause may also contain arithmetic expressions involving the operators +, −, ∗, and / operating on constants or attributes of tuples. . Demonstrate such a query on table below


Salary
1000
2000
3000
5000
10000




Q. “Find the names of all instructors in the Computer Science department who have salary greater than $70,000."


nameSalary
Pranav1000
Ajeet22000
Satish322000
Jayesh5000
Som70000



Queries on Multiple Relations:



Q: Retrieve the names of all instructors, along with their department names and department building name.





Q. For all instructors in the university who have taught some course, find their names and the course ID of all courses they taught.



Q. To find instructor names and course identifiers for instructors in the Computer Science department






The Natural Join:






Q. List the names of instructors along with the the titles of courses that they teach.


Previous Next