Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
It is a general purpose software system that facilitates processes of defining, constructing and manipulating databases for various applications DATABASE A DataBase is a collection of tables. SQL SQL (Structured Query Language) is a standard data access language used to interact with relational databases. Different databases differ in their support of SQL or add other features, but the core commands used to select, add, and modify data are common. Well probably use only the following standard types of SQL statements: A Select statement retrieves records. An Update statement modifies existing records. An Insert statement adds a new record. A Delete statement deletes existing records.
ADVANTAGES OF SQL SQL is a well-defined languages to interact with the database in a simple and efficient manner . SQL is an English like language as it uses words like Select, Insert ,Delete, From ,Where etc. As part of its command set. SQL is easy to learn and can manage complex problem. SQL provides a small and concise set of commands.
Table A Table is a collection of rows and columns. Entity An field name is called an entity Record The value of the field is called record Keys To mark constraints on the fields we use some keys. These are described below:Primary key Column or a set of columns that uniquely identify a row in a table must be unique and must have a value Foreign Key Column or set of columns which references the primary key or a unique key of another table Rows in two tables are linked by matching the values of the foreign key in one table with the values of the primary key in another
THREE TYPES OF SQL: DDL DDL is abbreviation of Data Definition Language. It is used to create and modify the structure of database objects in database. Examples: CREATE, ALTER, DROP statements DML DML is abbreviation of Data Manipulation Language. It is used to retrieve, store, modify, delete, insert and update data in database. Examples: SELECT, UPDATE, INSERT statements
DCL DCL is abbreviation of Data Control Language. It is used to create roles, permissions, and referential integrity as well it is used to control access to database by securing it. Examples: GRANT, REVOKE statements
QUERY 1: TO SHOW THE EXISTING DATABASES We key in, SHOW DATABASES; Result: Database Information_schema Performance_schema Mysql Test
QUERY 2: TO CREATE NEW DATABASES We key in, CREATE DATABASE COLLEGE; Result: new databases will be shown as
QUERY 3: TO USE NEW DATABASE We key in, USE COLLEGE; Result will be : database changed QUERY 4: TO CREATE TABLES IN NEW DATABASE We key in, CREATE TABLE STUDENT(ROLL_NO. INT PRIMARY KEY, NAME VAR CHAR(23), AGE INT(11), BRANCH_NAME INT(11));
QUERY 6: TO DESCRIBE TABLE STRUCTURE We key in, DESC STUDENT; Result: FIELD ROLL_NO NAME AGE TYPE Int(11) Varchar(23) Int(11) NULL KEY NO PRI YES YES YES DEFAULT NULL NULL NULL NULL EXTRA
BRANCH_ID Int(11)
INSERT INTO STUDENT VALUES(41,LOKESH,22,102); INSERT INTO STUDENT VALUES(42,SONAM,24,101); INSERT INTO STUDENT VALUES(20,POOJA,23,102); INSERT INTO STUDENT VALUES(40,NIBHA,21,101); INSERT INTO STUDENT VALUES(39, KAMALPREET,21,101); Result: ROLL_NO NAME AGE BRANCH_ID
20 39 40 41 42
23 21 21 22 24
QUERY 8: TO SELECT FROM TABLE USING WHERE CLAUSE We key in, SELECT ROLL_NO, NAME FROM STUDENT WHERE AGE<22;
QUERY 9: TO SELECT FROM TABLE USING BETWEEN CLAUSE We key in, SELECT * FROM STUDENT WHERE NAME BETWEEN L* AND P*; Result: ROLL_NO NAME AGE BRANCH_ID
40 41
NIBHA LOKESH
21 22
101 102
QUERY 10: TO SELECT FROM TABLE USING LIKE CLAUSE We key in, SELECT * FROM STUDENT WHERE NAME LIKE K%; RESULT: ROLL_NO 39 NAME AGE KAMALPREET 22 BRANCH_ID 101
QUERY 11: TO USE DISTINCT CLAUSE We key in, SELECT DISTINCT AGE FROM STUDENT; Result: AGE 21 22 23 24
QUERY 12: TO DELETE A ROW FROM A TABLE We key in, DELETE FROM STUDENT WHERE NAME LIKE K%; Result:
ROLL_NO
NAME
AGE
BRANCH_ID
20 40 41 42
23 21 22 24
QUERY 13: TO DELETE ALL ROWS FROM A TABLE The TRUNCATE command removes a table from the database We key in, TRUNCATE TABLE STUDENT; Result: Empty set
QUERY 14: TO DELETE A TABLE FROM A DATABASE The DROP command removes a table from the database We key in, DROP TABLE STUDENT; Result: Empty set
QUERY 15: TO USE ORDER BY CLAUSE SELECT* FROM STUDENT ORDER BYAGE; Result: ROLL_NO NAME AGE BRANCH_ID
40 41 20 42
21 22 23 24
QUERY 16: TO UPDATE ANY VALUE IN THE TABLE We key in, UPDATE STUDENT SET AGE=24 WHERE NAME=POOJA AND BRANCH_ID=102
40 41 20 42
21 22 24 24