제 2 장 SQL 활용.  SQL 활용 예제 (1) create table student ( id int not null, name char(20) not null, age int, height int, weight float, primary key(id) ); insert.

Slides:



Advertisements
Similar presentations
COP4540 Database Management System Midterm Review
Advertisements

ER to Relational Mapping. Logical DB Design: ER to Relational Entity sets to tables. CREATE TABLE Employees (ssn CHAR (11), name CHAR (20), lot INTEGER,
SQL2-ch2 管理綱要物件.
CSC343: Intro. to Databases1 Tutorial for CSC343 Introduction to Databases Fall 2006 Week 2.
Fundamentals of Database Systems Fourth Edition El Masri & Navathe
View (virtual table). View A VIEW is a virtual table A view contains rows and columns, just like a real table. The fields in a view are fields from one.
BACS 485—Database Management Advanced SQL Overview Advanced DDL, DML, and DCL Commands.
MySQL. To start go to Login details: login: labuser password:macimd15 – There.
Relational Database. Relational database: a set of relations Relation: made up of 2 parts: − Schema : specifies the name of relations, plus name and type.
6.830/6.814 Lecture 5 Database Internals Continued September 17, 2014.
OUTLINE OF THE LECTURE PART I GOAL: Understand the Data Definition Statements in Fig 4.1 Step1: Columns of the Tables and Data types. Step2: Single column.
SQL Lecture 10 Inst: Haya Sammaneh. Example Instance of Students Relation  Cardinality = 3, degree = 5, all rows distinct.
Fall 2005 ICS184/EECS116 – Notes 08 1 ICS 184/EECS116: Introduction to Data Management Lecture Note 8 SQL: Structured Query Language -- DDL.
Overview Begin 6:00 Quiz15 mins6:15 Review Table Terms25 mins6:40 Short Break10 mins6:50 SQL: Creating Tables60 mins7:50 Break10 mins8:00 Lab – Creating.
COP5725 – Principles of Database Management Systems
Remaining Topics in SQL to be covered… NULL values in SQL Outer joins in SQL Constraints and Triggers in SQL Embedded SQL.
Design process Identify entities and attributes –What do you want to know? –Note that the question of whether something is an attribute or an entity may.
Murali Mani SQL DDL and Oracle utilities. Murali Mani Datatypes in SQL INT (or) INTEGER FLOAT (or) REAL DECIMAL (n, m) CHAR (n) VARCHAR (n) DATE, TIME.
SQL Keys and Constraints Justin Maksim. Key Declaration Key constraint defined within the CREATE TABLE command Key can be declared using either the PRIMARY.
SQL DDL constraints Restrictions on the columns and tables 1SQL DDL Constraints.
Remaining Topics in SQL to be covered… NULL values in SQL Outer joins in SQL Constraints and Triggers in SQL Embedded SQL.
SQL - Part 2 Much of the material presented in these slides was developed by Dr. Ramon Lawrence at the University of Iowa.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems.
Constraints  Constraints are used to enforce rules at table level.  Constraints prevent the deletion of a table if there is dependencies.  The following.
4-1 Copyright  Oracle Corporation, All rights reserved. Data Manipulation Language (DML)
1 ICS 184: Introduction to Data Management Lecture Note 10 SQL as a Query Language (Cont.)
Onsdag The concepts in a relation data model SQL DDL DML.
-Software School of Hunan University-
Views. Logical data is how we want to see the current data in our database. Physical data is how this data is actually placed in our database.
1 ICS 184: Introduction to Data Management Lecture Note 11: Assertions, Triggers, and Index.
ACTION QUERIES (SQL COMMANDS ) STRUCTURED QUERY LANGUAGE.
Procedure Function Trigger. create table employee ( id number, name varchar2(100), deptno number, salary float, primary key(id) ) create table deptincrease.
SQL FUNDAMENTALS SQL ( Structured Query Language )
SQL Basics. 5/27/2016Chapter 32 of 19 Naming SQL commands are NOT case sensitive SQL commands are NOT case sensitive But user identifier names ARE case.
Database Management System Quiz 1. A company needs to store information about: the employees identified by EmpNo, Name, Salary and Phone; departments.
Recap of SQL Lab no 8 Advance Database Management System.
DatabaseDatabase cs453 Lab5 1 Ins.Ebtesam AL-Etowi.
Dec 8, 2003Murali Mani Constraints B term 2004: lecture 15.
Prince Sultan University Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems.
42 Example Join-- File Information 4 Emp( Fn Char(10), Minit Char, LN Char(20), SSN number(9), Bdate Date, Addr char(40), Sex Char, Salary Number(9,2),
COMP3030 Database Management System Final Review
COP-5725 Practice Exercises
ORDER BY clause in SELECT command: Normally, the result of the query will not be in ordered format. If we want to get the result of the query in specific.
Ch 7: Normalization-Part 1
CREATE TABLE ARTIST ( ArtistID int NOT NULL IDENTITY (1,1), Namechar(25) NOT NULL, TEXT ERROR Nationality char (30) NULL, Birthdate numeric (4,0) NULL,
Constraints and Views Chap. 3-5 continued (7 th ed. 5-7)
LECTURE FOUR Introduction to SQL DDL with tables DML with tables.
1 数据库系统概论 An Introduction to Database System 第三章 关系数据库标准语言 SQL ( 续 2 )
Chapter 10 SQL DDL.
The SQL Database Grammar
Chapter 4 Basic SQL.
Referential Integrity MySQL
Introduction to Database Systems, CS420
Remaining Topics in SQL to be covered…
Interacting with the Oracle Server
5-2-7 : تقسيم الصفوف في الجدول إلي مجموعات :-
جملة الاستعلام الأساسية
لغة قواعد البيانات STRUCTURED QUERY LANGUAGE SQL))
Session - 6 Sequence - 1 SQL: The Structured Query Language:
EXAMPLE Emp table: SS# Name Age Salary dno 1 Joe Mary 20
Database Design: Relational Model
ISC321 Database Systems I Chapter 4: SQL: Data definition, Constraints, and Basic Queries and Updates Fall 2015 Dr. Abdullah Almutairi.
Triggers.
Session - 6 Sequence - 1 SQL: The Structured Query Language:
Updating Databases With Open SQL
Turn on spool and save to file a.txt
Introduction to Relational databases
Integrity Constraints
Updating Databases With Open SQL
Practice Project Practice to know SQL
Presentation transcript:

제 2 장 SQL 활용

 SQL 활용 예제 (1) create table student ( id int not null, name char(20) not null, age int, height int, weight float, primary key(id) ); insert into student values(10, ‘ Kim', 40, 170, 68); insert into student values(20, ‘ Lee', 30, 175, 74); insert into student values(30, 'Park', 40, 165, 58); insert into student values(40, 'Choi', 50, 184, 87); select * from student;

 SQL 활용 예제 (1) insert into student values(40, 'Chung', 50, 154, null); //error insert into student values(50, 20, ‘ Chung', 154, null); //error insert into student values(50, 'Chung', 30, 154, null); insert into student values(null, 'Lim', 50, 162, null); //error select * from student; idnameageheightweight 10Kim Lee Park Choi

 SQL 활용 예제 (1) select name, age from student where height >= 170 and weight <= 80; select max(height), avg(height), min(height) from student; select age, avg(height), avg(weight) from student group by age; idnameageheightweight 10Kim Lee Park Choi

 SQL 활용 예제 (1) update student set age = 45, height = 165 where id = 30; delete from student where age <= 40; delete from student; select * from student; drop table student; select * from student; idnameageheightweight 10Kim Lee Park Choi

 SQL 활용 예제 (2) create table dept ( dno int not null, dname char(20) not null, dname char(20) not null, mgreno int, mgreno int, mgrstartdate char(10), mgrstartdate char(10), primary key(dno) ) ; primary key(dno) ) ; create table emp ( eno int not null, ename char(20) not null, ename char(20) not null, sex char(1), sex char(1), salary int, salary int, dno int, dno int, primary key(eno), primary key(eno), foreign key(dno) references dept(dno) ); foreign key(dno) references dept(dno) );

 SQL 활용 예제 (2) select ename, salary, dno from emp select ename, salary from emp where salary >=20000 select ename, salary from emp where salary >=20000 and dno = 2 select dno from dept where dname = 'Research'

 SQL 활용 예제 (2) select dname, ename from emp, dept where mgreno = eno select ename, dname from emp, dept where emp.dno = dept.dno and dname='Research‘ select ename, salary from emp where dno in (select dno from dept where dname = 'Research') select ename, salary from emp where exists (select * from dept where dno = emp.dno and dname = 'Research')

 SQL 활용 예제 (2) update emp set dno = 5 where eno = 100; // 참조 무결성 위반 delete from dept where dno = 1; // 참조 무결성 위반 update dept set dno = 6 where dno = 1; // 참조 무결성 위반

 SQL 활용 예제 (2) create table emp ( eno int not null, ename char(20) not null, ename char(20) not null, sex char(1), sex char(1), salary int, salary int, dno int, dno int, primary key(eno), primary key(eno), foreign key(dno) references dept(dno) foreign key(dno) references dept(dno) on delete set null on update cascade); on delete set null on update cascade);

 SQL 활용 예제 (2) update emp set dno = 5 where eno = 100; // 참조 무결성 위반 delete from dept where dno = 1; //emp 의 dno 가 1 이 null 바뀜 update dept set dno = 6 where dno = 1; // emp 의 dno 가 1 이 6 으로 바뀜