The document describes several SQL commands used to create tables, insert data, and run queries on the tables. It includes:
1) Creating a student table with attributes like ID, class, section, etc and linking it to a parent table using foreign keys.
2) Inserting details of 15 students into the student table.
3) Examples of creating tables with different data types and constraints like primary keys, foreign keys, checks and displaying the contents.
4) Examples of using logical operations like >, <, = in queries to select records matching various conditions from the tables.
Download as TXT, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
17 views
SQL
The document describes several SQL commands used to create tables, insert data, and run queries on the tables. It includes:
1) Creating a student table with attributes like ID, class, section, etc and linking it to a parent table using foreign keys.
2) Inserting details of 15 students into the student table.
3) Examples of creating tables with different data types and constraints like primary keys, foreign keys, checks and displaying the contents.
4) Examples of using logical operations like >, <, = in queries to select records matching various conditions from the tables.
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 11
#PRACTICAL_1:- TO OPERATE DATABASE RELATED COMMANDS AND USE OF COMMENTS.
#PRACTICAL_2:- TO CREATE A STUDENT TABLE WITH THE STUDENT
ID,CLASS,SECTION,GENDER,NAME,DOB,ROLLNO AND MARKS AS ATTRIBUTES WHERE THE STUDENTS ID IS THE PRIMARY KEY. PARENT ID IS FOREGIN KEY FROM PARENT TABLE. TO CREATE A PARENT TABLE WITH THE PARENT ID,NAME,DOB,ANNUAL_INCOME,ADDRESS AS ATTRIBUTES WHERE THE PARENT ID IS THE PRIMARY KEY.
mysql> CREATE TABLE parent
-> ( -> PRENT_ID INT PRIMARY KEY, -> NAME VARCHAR(20), -> DOB DATE, -> ANNUAL_INCOME INT , -> ADDRESS VARCHAR(30) -> ); Query OK, 0 rows affected (0.07 sec)
mysql> DESC parent;
+---------------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +---------------+-------------+------+-----+---------+-------+ | PRENT_ID | int | NO | PRI | NULL | | | NAME | varchar(20) | YES | | NULL | | | DOB | date | YES | | NULL | | | ANNUAL_INCOME | int | YES | | NULL | | | ADDRESS | varchar(30) | YES | | NULL | | +---------------+-------------+------+-----+---------+-------+ 5 rows in set (0.05 sec) mysql> CREATE TABLE STUDENT -> ( -> STU_ID INT PRIMARY KEY, -> NAME VARCHAR(20), -> CLASS CHAR(2), -> SECT CHAR(1), -> ROLL_NO INT, -> DOB DATE, -> GENDER CHAR(1), -> PRENT_ID INT REFERENCES parent(PRENT_ID) -> ); Query OK, 0 rows affected (0.03 sec)
#PRACTICAL_3:- TO INSERT THE DETALIS OF 15 STUDENTS IN THE TABLE CREATED IN P2.
INSTRUCTION:-Choose Section from A/B/C Enter maximum marks 100. Some students must above 50. Some students must born in 2005. Roll number range from 1 to 15 DISPLAY THE ENTIRE CONTENT OF BOTH TABLE.