This is a refresher course. I already have a diploma in Oracle RDBMS.
Structured Query Language
- A language for relational databases
- Used to query data
- Data needs to be secured, and accessed when required.
- The above can be achieved using a Database.
- Is a repository of data / it is a program that stores data.
- Provides functionality for adding, modifying and querying data.
- Relational database
- Data is stored in tabular form - columns & rows
- Like in spreadsheet
- Cols - has properties about each item - such as last name, first name, email address, etc.
- Table is a collection of related things - example employees, salary, etc.
- In a relational database, you can form relationship between tables.
- Emp table, Salary table, etc. etc.
- RDBMS
- DMBS
- Database Management System - set of software tools for the data in the database is called DBMS.
- Database is a repository of data
- Terms database, database server, database system, data server, DBMS are all used interhangeably.
- MySQL, DB2, Oracle
- Create table
- Insert data to a table
- Select statement to see the data in a table
- Update data in a table
- Delete data from the table
- Select col1, col2, col3 from FilmLocations;
- Select * from FilmLocations;
- Select count(*) from FilmLocations;
- Select DISTINCT(Directors) from FilmLocations;
- Select * from FilmLocations LIMIT 25;
- SELECT DISTINCT Title FROM FilmLocations WHERE ReleaseYear=2015 LIMIT 3 OFFSET 5; Retrieve the next 3 film names distinctly after first 5 films released in 2015.
- Insert into TableName ColumnName1, ColumnName2, ColumnNameN values <Value1>, <Value2>, <ValueN>;
- Inserting 1 row at a time:
- Insert into AUTHOR (Author_ID, Lastname, Firstname, Email, City, Country) values ('A1', 'Chong', 'Raul', 'rfc@ibm.com', 'Toronto', 'CA');
- Multiple rows can be inserted.
- Insert into Author (Author_ID, Lastname, Firstname, Email, City, Country)
- Insert into Instructor(ins_id, lastname, firstname, city, country) VALUES (8, 'Ryan', 'Steve', 'Barlby', 'GB'), (9, 'Sannareddy', 'Ramesh', 'Hyderabad', 'IN');
- Alter data in a table using UPDATE statement.
- Update TableName SET ColumnName1=Value1 WHERE [condition];
- Example, Update AUTHOR SET Lastname='KATTA', Firstname='Lakshmi' WHERE AUTHOR_Id='A2';
- If where clause is not specified all rows will be updated.
- Read and modify data.
- Delete from TableName WHERE <condition>;
- Delete from AUTHOR WHERE Author_ID in (a1, a2); both the rows will be deleted.
- If where clause is not specified all rows will be deleted.
- Entity Book becomes a table in a database.
- Attributes become the columns.
- DDL - define, change and drop data.
- CREATE
- ALTER
- TRUNCATE
- DROP
- DML - read and modify data in tables.
- Also known as CRUD operations.
- INSERT
- SELECT
- UPDATE
- DELETE
- Alter
- Add / Remove columns
- Modify datatype of a col
- Add / remove keys
- Add / remove constraints
Alter table AUTHORAdd Qualification varchar(30);
Delete cols
Alter table BOOK
drop COLUMN Qual;
Modify datatype of a col
ALTER TABLE AUTHOR
ALTER COLUMN Qualification VARCHAR(4); //Instead of Varchar(30) or you can modify datatype to another (string to int, etc.).
Constraints
Create table myKeyConstraints (
sno int PRIMARY KEY NOT NULL,
firstname varchar(30),
lastname varchar(30)
);
sp_help mykeyconstraints; // Check the constraint name highlighted below....
No comments:
Post a Comment