SELECT e.NationalIDNumber, p.FirstName,p.LastName, City FROM HumanResources.Employee e INNER JOIN Person.Person p on p.BusinessEntityID = e.BusinessEntityID.

Slides:



Advertisements
Similar presentations
آموزش SQL Server 2005.
Advertisements

Relational Database. Relational database: a set of relations Relation: made up of 2 parts: − Schema : specifies the name of relations, plus name and type.
SQL Lecture 10 Inst: Haya Sammaneh. Example Instance of Students Relation  Cardinality = 3, degree = 5, all rows distinct.
Module 4: Creating Data Types and Tables. Overview Creating Data Types Creating Tables Generating Column Values Generating Scripts.
10 Copyright © Oracle Corporation, All rights reserved. Including Constraints.
Creating and Altering Tables cis 407 Object Names Create Statement Alter statement Drop Statement.
Introduction to Relational Database ISYS 464. Introduction to Relational Model Data is logically structured within relations. Each relation is a table.
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 DDL constraints Restrictions on the columns and tables 1SQL DDL Constraints.
Structured Query Language. Brief History Developed in early 1970 for relational data model: –Structured English Query Language (SEQUEL) –Implemented with.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 4-1 David M. Kroenke Database Processing Chapter 7 Structured Query Language.
Creating a Database Microsoft SQL Server. Create Database SQL Management Studio 1.In Object Explorer, connect to an instance of the SQL Server Database.
Database Constraints. Database constraints are restrictions on the contents of the database or on database operations Database constraints provide a way.
A Guide to SQL, Eighth Edition Chapter Three Creating Tables.
SQL in Action Amit Bhawnani & Nimesh Shah. Basic Structure SQL is based on set and relational operations with certain modifications and enhancements A.
SQL Data Definition (CB Chapter 6) CPSC 356 Database Ellen Walker Hiram College (Includes figures from Database Systems by Connolly & Begg, © Addison Wesley.
SQL data definition using Oracle1 SQL Data Definition using Oracle.
Databases in Visual Studio. Database in VisualStudio An MS SQL database are built in Visual studio The Name can be something like ”(localdb)\Projects”
Structured Query Language. Brief History Developed in early 1970 for relational data model: –Structured English Query Language (SEQUEL) –Implemented with.
Company LOGO 1 Database Creation and Maintenance Jorge G. Martinez.
Fundamentals, Design, and Implementation, 9/e CPE 481 Database Processing Chapter 6 Structured Query Language (SQL) Instructor:Suthep Madarasmi, Ph.D.
SQL data definition using Oracle1 SQL Data Definition using Oracle.
10 Copyright © 2009, Oracle. All rights reserved. Using DDL Statements to Create and Manage Tables.
1 Copyright © 2006, Oracle. All rights reserved. Using DDL Statements to Create and Manage Tables.
Copyright © 2004, Oracle. All rights reserved. Using DDL Statements to Create and Manage Tables.
10 Copyright © Oracle Corporation, All rights reserved. Including Constraints.
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.
SQL: DDL. SQL Statements DDL - data definition language –Defining and modifying data structures (metadata): database, tables, views, etc. DML - data manipulation.
Recap of SQL Lab no 8 Advance Database Management System.
Intro to SQL| MIS 2502  Spacing not relevant › BUT… no spaces in an attribute name or table name  Oracle commands keywords, table names, and attribute.
SQL Basics. What is SQL? SQL stands for Structured Query Language. SQL lets you access and manipulate databases.
CS 3630 Database Design and Implementation. Database Schema Branch (Bno…) Staff (Sno…Bno) Owner (Ono…) PropertyForRent (Pno…Ono) Renter (Rno…) Viewing.
Dec 8, 2003Murali Mani Constraints B term 2004: lecture 15.
Constraints cis 407 Types of Constraints & Naming Key Constraints Unique Constraints Check Constraints Default Constraints Misc Rules and Defaults Triggers.
Tables and Constraints Oracle PL/SQL. Datatypes The SQL Data Definition Language Commands (or DDL) enable us to create, modify and remove database data.
Chapter 9 Constraints. Chapter Objectives  Explain the purpose of constraints in a table  Distinguish among PRIMARY KEY, FOREIGN KEY, UNIQUE, CHECK,
Oracle 11g: SQL Chapter 4 Constraints.
10 Copyright © Oracle Corporation, All rights reserved. Including Constraints.
CREATE TABLE CREATE TABLE statement is used for creating relations Each column is described with three parts: column name, data type, and optional constraints.
Chapter 4 Constraints Oracle 10g: SQL. Oracle 10g: SQL 2 Objectives Explain the purpose of constraints in a table Distinguish among PRIMARY KEY, FOREIGN.
SQL introduction 2013.
INCLUDING CONSTRAINTS lecture5. Outlines  What are Constraints ?  Constraint Guidelines  Defining Constraint  NOT NULL constraint  Unique constraint.
IMS 4212: Data Manipulation 1 Dr. Lawrence West, MIS Dept., University of Central Florida Additional Data Manipulation Statements INSERT.
© 2002 by Prentice Hall 1 David M. Kroenke Database Processing Eighth Edition Chapter 9 Structured Query Language.
1 DBS201: More on SQL Lecture 3. 2 Agenda How to use SQL to update table definitions How to update data in a table How to join tables together.
IS 380 Introduction to SQL This lectures covers material from: database textbook chapter 3 Oracle chapter: 3,14,17.
Agenda for Class 2/02/2006 Finish discussing constraints generated with the CREATE TABLE statement. Discuss DROP statement. Discuss INSERT, COMMIT, DELETE,
1 SQL Insert Update Delete Create table Alter table.
Including Constraints. What Are Constraints? Constraints enforce rules at the table level. You can use constraints to do the following: – Enforce rules.
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,
CREATE DATABASE database_name [ON [PRIMARY] [( [ NAME = logical_file_name,] [ FILENAME = ‘ os_file_name’] [, SIZE = size] [, MAXSIZE = {max_size|UNLIMITED}]
Constraints and Views Chap. 3-5 continued (7 th ed. 5-7)
1 Designing Tables for a Database System. 2 Where we were, and where we’re going The Entity-Relationship model: Used to model the world The Relational.
Lec-7. The IN Operator The IN operator allows you to specify multiple values in a WHERE clause. SQL IN Syntax SELECT column_name(s) FROM table_name WHERE.
Advanced SQL - DDL Advanced Database Dr. AlaaEddin Almabhouh.
In this session, you will learn to: Manage databases Manage tables Objectives.
Database Constraints Ashima Wadhwa. Database Constraints Database constraints are restrictions on the contents of the database or on database operations.
Fundamentals of DBMS Notes-1.
Database Constraints Ashima Wadhwa.
CS 3630 Database Design and Implementation
Designing Tables for a Database System
DATABASE SQL= Structure Query Language مبادئ قواعد بيانات
Module 5: Implementing Data Integrity by Using Constraints
Lecturer: Mukhtar Mohamed Ali “Hakaale”
لغة قواعد البيانات STRUCTURED QUERY LANGUAGE SQL))
DATABASE SQL= Structure Query Language مبادئ قواعد بيانات
Assignment: SQL #2 Putting Information into a Database
View ایحاد وتغییر Viewایجاد ایندکس روی
Including Constraints
កម្មវិធីបង្រៀន SQL Programming ជាភាសាខ្មែរ Online SQL Training Course
Presentation transcript:

SELECT e.NationalIDNumber, p.FirstName,p.LastName, City FROM HumanResources.Employee e INNER JOIN Person.Person p on p.BusinessEntityID = e.BusinessEntityID INNER JOIN Person.BusinessEntityAddress a on p.BusinessEntityID = a.BusinessEntityID INNER JOIN Person.Address pa on pa.AddressID = a.AddressID

CREATE DATABASE مثال از دستور CREATE DATABASE Accounting ON (NAME = 'Accounting', FILENAME = 'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\Acco untingData.mdf‘, SIZE = 10, MAXSIZE = 50, FILEGROWTH = 5)

CREATE DATABASE ادامه دستور LOG ON (NAME = 'AccountingLog', FILENAME = 'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\Accounti ngLog.ldf', SIZE = 5MB, MAXSIZE = 25MB, FILEGROWTH = 5MB); GO EXEC sp_helpdb ‘Accounting’

Sp-helpdb نتيجه اجرای

USE Accounting CREATE TABLE Customers ( CustomerNo int IDENTITY NOT NULL, CustomerName varchar(30) NOT NULL, Address1 varchar(30) NOT NULL, Address2 varchar(30) NOT NULL, City varchar(20) NOT NULL, State char(2) NOT NULL, Zip varchar(10) NOT NULL, Contact varchar(25) NOT NULL, Phone char(15) NOT NULL, FedIDNo varchar(9) NOT NULL, DateInSystem smalldatetime NOT NULL )

Sp_help استفاده از EXEC sp_help Customers

ALTER DATABASE تغيير مشخصات ديتابيس با ALTER DATABASE Accounting MODIFY FILE (NAME = Accounting, SIZE = 100MB) ALTER TABLE Employees ADD PreviousEmployer varchar(30) NULL ALTER TABLE Employees ADD DateOfBirth date NULL, LastRaiseDate date NOT NULL DEFAULT ‘ ’

EXEC sp_help Employees

DROP استفاده از دستور USE Accounting DROP TABLE Customers, Employees USE master DROP DATABASE Accounting

انواع قيد ها Primary key Foreign key Unique (also known as alternate keys) Check Default Rules Defaults (similar to default constraints)

انواع جامعيت

USE Accounting; CREATE TABLE Customers( CustomerNo int IDENTITY NOT NULL PRIMARY KEY, CustomerName varchar(30) NOT NULL, Address1 varchar(30) NOT NULL, Address2 varchar(30) NOT NULL, City varchar(20) NOT NULL, State char(2) NOT NULL, Zip varchar(10) NOT NULL, Contact varchar(25) NOT NULL, Phone char(15) NOT NULL, FedIDNo varchar(9) NOT NULL, DateInSystem smalldatetime NOT NULL);

USE Accounting ALTER TABLE Employees ADD CONSTRAINT PK_EmployeeID PRIMARY KEY (EmployeeID);

USE Accounting CREATE TABLE Orders ( OrderID int IDENTITY NOT NULL PRIMARY KEY, CustomerNo int NOT NULL FOREIGN KEY REFERENCES Customers(CustomerNo), OrderDate date NOT NULL, EmployeeID int NOT NULL);

EXEC sp_helpconstraint

ALTER TABLE Orders ADD CONSTRAINT FK_EmployeeCreatesOrder FOREIGN KEY (EmployeeID) REFERENCES Employees(EmployeeID);

ALTER TABLE Employees ADD CONSTRAINT FK_EmployeeHasManager FOREIGN KEY (ManagerEmpID) REFERENCES Employees(EmployeeID);

CREATE TABLE Employees ( EmployeeID int IDENTITY NOT NULL PRIMARY KEY, FirstName varchar (25) NOT NULL, MiddleInitial char (1) NULL, LastName varchar (25) NOT NULL, Title varchar (25) NOT NULL, SSN varchar (11) NOT NULL, Salary money NOT NULL, PriorSalary money NOT NULL, LastRaise AS Salary -PriorSalary, HireDate smalldatetime NOT NULL, TerminationDate smalldatetime NULL, ManagerEmpID int NOT NULL REFERENCES Employees(EmployeeID), Department varchar (25) NOT NULL);

FOREIGN KEY قيدهای CREATE TABLE OrderDetails( OrderID int NOT NULL, PartNo varchar(10) NOT NULL, Description varchar(25) NOT NULL, UnitPrice money NOT NULL, Qty int NOT NULL, CONSTRAINT PKOrderDetails PRIMARY KEY (OrderID, PartNo), CONSTRAINT FKOrderContainsDetails FOREIGN KEY (OrderID) REFERENCES Orders(OrderID) ON UPDATE NO ACTION ON DELETE CASCADE);

UNIQUE قيد های CREATE TABLE Shippers( ShipperID int IDENTITY NOT NULL PRIMARY KEY, ShipperName varchar(30) NOT NULL, Address varchar(30) NOT NULL, City varchar(25) NOT NULL, State char(2) NOT NULL, Zip varchar(10) NOT NULL, PhoneNo varchar(14) NOT NULL UNIQUE);

ALTER TABLE Employees ADD CONSTRAINT AK_EmployeeSSN UNIQUE (SSN);

CHECK انواع قيد Limit Month column to appropriate numbers BETWEEN 1 AND 12 Proper SSN formatting LIKE ‘[0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9][0-9]’ Limit to a specific list ofShippers IN (‘UPS’, ‘Fed Ex’, ‘USPS’) Price must be positive UnitPrice >= 0 Referencing another column in the same row ShipDate >= OrderDate

ALTER TABLE Customers ADD CONSTRAINT CN_CustomerDateInSystem CHECK (DateInSystem <= GETDATE ());

DEFAULT استفاده از قيد CREATE TABLE Shippers ( ShipperID int IDENTITY NOT NULL PRIMARY KEY, ShipperName varchar(30) NOT NULL, DateInSystem smalldatetime NOT NULL DEFAULT GETDATE () );

ALTER TABLE Customers ADD CONSTRAINT CN_CustomerDefaultDateInSystem DEFAULT GETDATE() FOR DateInSystem; ALTER TABLE Customers ADD CONSTRAINT CN_CustomerAddress DEFAULT ‘UNKNOWN’ FOR Address1;

CHECK قيد ALTER TABLE Customers WITH NOCHECK ADD CONSTRAINT CN_CustomerPhoneNo CHECK (Phone LIKE ‘([0-9][0-9][0-9]) [0-9][0-9][0-9]-[0-9][0- 9][0-9][0-9]‘);

غير فعال کردن يک قيد ALTER TABLE Customers NOCHECK CONSTRAINT CN_CustomerPhoneNo;

Rule ايجاد و انتساب CREATE RULE SalaryRule > 0; EXEC sp_helptext SalaryRule; EXEC sp_bindrule ‘SalaryRule’, ‘Employees.Salary’; EXEC sp_unbindrule ‘Employees.Salary’;

DEFAULT ايجاد و انتساب CREATE DEFAULT SalaryDefault AS 0; EXEC sp_bindefault ‘SalaryDefault’, ‘Employees.Salary’; EXEC sp_unbindefault ‘Employees.Salary’;