Company LOGO 1 Database Creation and Maintenance Jorge G. Martinez.

Slides:



Advertisements
Similar presentations
By: Jose Chinchilla July 31, Jose Chinchilla MCITP: SQL Server 2008, Database Administrator MCTS: SQL Server 2005/2008, Business Intelligence DBA.
Advertisements

Advantage Data Dictionary. agenda Creating and Managing Data Dictionaries –Tables, Indexes, Fields, and Triggers –Defining Referential Integrity –Defining.
Brian Alderman | MCT, CEO / Founder of MicroTechPoint Pete Harris | Microsoft Senior Content Publisher.
Let’s try Oracle. Accessing Oracle The Oracle system, like the SQL Server system, is client / server. For SQL Server, –the client is the Query Analyser.
SQL components In Oracle. SQL in Oracle SQL is made up of 4 components: –DDL Data Definition Language CREATE, ALTER, DROP, TRUNCATE. Creates / Alters.
Fundamentals, Design, and Implementation, 9/e Chapter 11 Managing Databases with SQL Server 2000.
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.
Oracle SQL*plus John Ortiz. Lecture 10SQL: Overview2 Overview  SQL: Structured Query Language, pronounced S. Q. L. or sequel.  A standard language for.
SQL Overview Defining a Schema CPSC 315 – Programming Studio Spring 2008 Project 1, Lecture 3 Slides adapted from those used by Jeffrey Ullman, via Jennifer.
Module 7: Restoring Databases. Overview SQL Server Recovery Process Preparing to Restore a Database Restoring Backups Restoring Databases from Different.
1 Nassau Community CollegeProf. Vincent Costa Acknowledgements: Introduction to Database Management, All Rights ReservedIntroduction to Database Management.
Working with SQL and PL/SQL/ Session 1 / 1 of 27 SQL Server Architecture.
1 Chapter Overview Understanding Backup Terms, Media, and Devices Backing Up Databases, Files, Filegroups, and Transaction Logs Restoring a User Database.
Phonegap Bridge – File System CIS 136 Building Mobile Apps 1.
SQL Overview Defining a Schema CPSC 315 – Programming Studio Slides adapted from those used by Jeffrey Ullman, via Jennifer Welch Via Yoonsuck Choe.
SQL Basics. SQL SQL (Structured Query Language) is a special-purpose programming language designed from managing data in relational database management.
A Guide to SQL, Eighth Edition Chapter Three Creating Tables.
© 2002 by Prentice Hall 1 David M. Kroenke Database Processing Eighth Edition Chapter 13 Managing Databases with SQL Server 2000.
Chapter 4 SQL. SQL server Microsoft SQL Server is a client/server database management system. Microsoft SQL Server is a client/server database management.
Project Implementation for COSC 5050 Distributed Database Applications Lab2.
DBA Developer. Responsibilities  Designing Relational databases  Developing interface layer Environment Microsoft SQL Server,.NET SQL Layer: Stored.
LOGO 1 Lab_02: Basic SQL. 2 Outline  Database Tables  SQL Statements  Semicolon after SQL Statements?  SQL DML and DDL  SQL SELECT Statement  SQL.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
RDB/1 An introduction to RDBMS Objectives –To learn about the history and future direction of the SQL standard –To get an overall appreciation of a modern.
Databases in Visual Studio. Database in VisualStudio An MS SQL database are built in Visual studio The Name can be something like ”(localdb)\Projects”
Database Technical Session By: Prof. Adarsh Patel.
CS 3630 Database Design and Implementation. Your Oracle Account UserName is the same as your UWP username Followed Not case sensitive Initial.
© 2007 by Prentice Hall (Hoffer, Prescott & McFadden) 1 Introduction to SQL.
© 2009 Pearson Education, Inc. Publishing as Prentice Hall 1 UNIT 6: Chapter 7: Introduction to SQL Modern Database Management 9 th Edition Jeffrey A.
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
SQL Data Definition Language (DDL) Using Microsoft SQL Server 1SDL Data Definition Language (DDL)
FEN  Data Definition: CREATE TABLE, ALTER TABLE  Data Manipulation: INSERT, UPDATE, DELETE  Queries: SELECT SQL: Structured Query Language.
Today’s Topics Backup Recap Restoration and Recovery T-SQL Commands –INSERT –UPDATE –DELETE –BEGIN TRAN –COMMIT TRAN –ROLLBACK TRAN.
SQL: DDL. SQL Statements DDL - data definition language –Defining and modifying data structures (metadata): database, tables, views, etc. DML - data manipulation.
Application Data and Database Activities Auditing Dr. Gabriel.
© 2009 Pearson Education, Inc. Publishing as Prentice Hall 1 Chapter 7 (Part a): Introduction to SQL Modern Database Management 9 th Edition Jeffrey A.
Introduction to Oracle. Oracle History 1979 Oracle Release client/server relational database 1989 Oracle Oracle 8 (object relational) 1999.
SQL Basics. What is SQL? SQL stands for Structured Query Language. SQL lets you access and manipulate databases.
SQL Structured Query Language 1. Data Definition Language (DDL) is used to manage table and define data structure i.e. CREATE, ALTER, DROP Data Control.
Visual Programing SQL Overview Section 1.
SQL Jan 20,2014. DBMS Stores data as records, tables etc. Accepts data and stores that data for later use Uses query languages for searching, sorting,
Instructor: Craig Duckett Lecture 12: Tuesday, May 19, 2015 Intro to SQL Server, SSMS 1.
Learningcomputer.com SQL Server 2008 –Views, Functions and Stored Procedures.
Relational Database Management System(RDBMS) Structured Query Language(SQL)
IS6146 Databases for Management Information Systems Lecture 3: SQL III – The DDL Rob Gleasure robgleasure.com.
Distribution of Marks For Second Semester Internal Sessional Evaluation External Evaluation Assignment /Project QuizzesClass Attendance Mid-Term Test Total.
Starting with Oracle SQL Plus. Today in the lab… Connect to SQL Plus – your schema. Set up two tables. Find the tables in the catalog. Insert four rows.
SSMS SQL Server Management System. SQL Server Microsoft SQL Server is a Relational Database Management System (RDBMS) Relational Database Management System.
Installation Oracle 11g Express 2 double click the "setup" button to install the Oracle.
1 Database Fundamentals Introduction to SQL. 2 SQL Overview Structured Query Language The standard for relational database management systems (RDBMS)
Introduction to Core Database Concepts Getting started with Databases and Structure Query Language (SQL)
Log Shipping, Mirroring, Replication and Clustering Which should I use? That depends on a few questions we must ask the user. We will go over these questions.
CS320 Web and Internet Programming SQL and MySQL Chengyu Sun California State University, Los Angeles.
Introduction to MySQL  Working with MySQL and MySQL Workbench.
Understand Data Definition Language (DDL) Database Administration Fundamentals LESSON 1.4.
SQL Basics Review Reviewing what we’ve learned so far…….
In this session, you will learn to: Manage databases Manage tables Objectives.
2 Copyright © 2009, Oracle. All rights reserved. Managing Schema Objects.
Agenda for Today  DATABASE Definition What is DBMS? Types Of Database Most Popular Primary Database  SQL Definition What is SQL Server? Versions Of SQL.
Understanding Core Database Concepts Lesson 1. Objectives.
DBMS Programs MS SQL Server & MySQL
Rob Gleasure robgleasure.com
Chapter 5 Introduction to SQL.
Rob Gleasure robgleasure.com
CS320 Web and Internet Programming SQL and MySQL
Database systems Lecture 3 – SQL + CRUD
SQL Fundamentals in Three Hours
CS3220 Web and Internet Programming SQL and MySQL
Chapter 11 Managing Databases with SQL Server 2000
CS3220 Web and Internet Programming SQL and MySQL
Presentation transcript:

Company LOGO 1 Database Creation and Maintenance Jorge G. Martinez

2 Agenda 1. Overview of MS SQL Managing Databases 3. DDL: Create, Alter, Drop 4. DML: Select, Insert, Delete, Update 5. SSMS: Demos

3 Overview of MS SQL 2005 (Structured Query Language)  SQL server is relatively easy to manage  SQL server scales from a mobile laptop to symmetric multiprocessor (SMP) systems.  SQL server provides business intelligence features that until now have only been available in Oracle.  Different editions of SQL 2005: Express, Workgroup, Standard, and Enterprise Edition.  SQL Server 2005 Express Edition allows you to run database applications on desktop and small servers. It is the updated version of MSDE and it is free.

4 Managing Databases  Transact-SQL or T-SQL  (SSMS) SQL Server Management Studio and its component Object Explorer

5 SQL Database language SQL contains two sublanguages  Data definition language (DDL)  Data manipulation language (DML)

6 Data definition language (DDL)  DDL contains three generic SQL statements:  CREATE object  ALTER object  DROP object

7 CREATE statement Use master CREATE DATABASE sample CREATE TABLE sample

8 ALTER statement USE northwind ALTER TABLE employee ADD telephone_no CHAR(12) NULL

9 DROP statement USE northwind ALTER TABLE employees DROP COLUMN telephone_no

10 Data manipulation language (DML) DML encompasses four generic operations for manipulating the database  SELECT  INSERT  DELETE  UPDATE

11 SELECT statement Ex1.USE northwind SELECT * from employees Ex2. USE northwind SELECT EmployeeID,LastName,FirstName, Title FROM Employees Ex3. Use northwind SELECT EmployeeID,OrderID FROM orders WHERE EmployeeID =‘5’ AND ShipVia =‘3’

12 INSERT statement USE northwind INSERT INTO region VALUES (5,'America')

13 DELETE statement  Deletes any employee with last name king in the employees table from the database name northwind. USE northwind DELETE FROM Employees WHERE LastName= 'King'

14 UPDATE statement USE northwind UPDATE Employees SET Title= 'District Manager' WHERE LastName ='Buchanan'

15 Creating Database Objects Using T-SQL DDL (Data Definition Language)  A database is the main container for tables, views, indexes stored procedures, and other database objects.  Using the CREATE DATABASE statement, you can create a new database along with the files used to store the database.  You can create 32,767 databases on an instance of SQL server.  CREATE DATABASE MyNewDatabase

16 Cont.  When the database is created, two files are also created: a primary file (an.mdf file) and a transaction log file (an.ldf file).  Its is recommended to keep these files in different drives to simplify recovering the database in case of corruption. Two Files  MyNewDatabase.mdf  MyNewDatabase.ldf

17 Cont. Sample showing two files

18 Code designating the.mdf and.ldf file locations.  CREATE DATABASE MyNewDatabase  ON Primary (Name = MyNewDatabase, Filename = 'C:\DBData\MyNewDatabase.mdf', Size= 100MB, MaxSize= 200MB, FileGrowth= 10%)  LOG ON (Name = MyNewDatabase_Log, Filename = 'D:\DBData\MyNewDatabase_Log.Ldf', Size= 30MB, MaxSize= 50MB, FileGrowth= 10%)

19 Removing Database Objects  All Transact-SQL statements to remove a database object have the general form :  DROP object object_name  DROP DATABASE database1 {,database2…}  It remove one or more databases.  One or more tables can be removed from a database with the following statement:  DROP TABLE table_name1 {,table_name2…}

20 Tables  Tables are objects that contain data.  In SQL server 2005, you can create up to two billion tables per database  CREATE TABLE statement creates a database table CREATE TABLE WAREHOUSE (HouseID INT PRIMARY KEY, HouseName char (50))

21 Tables Cont. CREATE TABLE Employees (EmployeeID INT Primary Key, LastName nvarchar(20), FirstName nvarchar(25), MiddleName nvarchar(25), Username nvarchar(25), Password nchar(10), nvarchar(30))

22 Tables Cont.  Create table Client  (Customer# NUMBER(4) PRIMARY KEY,  LastName VARCHAR2(10),  FirstName VARCHAR2(10),  Address VARCHAR2(20),  City VARCHAR2(12),  State VARCHAR2(2),  Zip VARCHAR2(5),  Referred NUMBER(4));  INSERT INTO CUSTOMERS  VALUES (1001, 'MORALES', 'BONITA', 'P.O. BOX 651', 'EASTPOINT', 'FL', '32328', NULL);  INSERT INTO CUSTOMERS  VALUES (1002, 'THOMPSON', 'RYAN', 'P.O. BOX 9835', 'SANTA MONICA', 'CA', '90404', NULL);  INSERT INTO CUSTOMERS  VALUES (1003, 'SMITH', 'LEILA', 'P.O. BOX 66', 'TALLAHASSEE', 'FL', '32306', NULL);  INSERT INTO CUSTOMERS  VALUES (1004, 'PIERSON', 'THOMAS', '69821 SOUTH AVENUE', 'BOISE', 'ID', '83707', NULL);  INSERT INTO CUSTOMERS  VALUES (1005, 'GIRARD', 'CINDY', 'P.O. BOX 851', 'SEATTLE', 'WA', '98115', NULL);  INSERT INTO CUSTOMERS  VALUES (1006, 'CRUZ', 'MESHIA', '82 DIRT ROAD', 'ALBANY', 'NY', '12211', NULL);

23 SQL 2005 Data Types

24 ISO –International Organization for Standardization.  The ISO synonyms for nchar are national char and national character.  The ISO synonyms for nvarchar are national char varying and national character varying.

25 (SSMS) SQL Server Management Studio  From Database choose  New Database  Choose a name for the new database Optional  Change the settings for the data file and the log file Autogrowth, etc  Change the general database options Auto create statistics, etc

26 Creating a new database (1)

27 Cont.

28 Creating a new database (2)  After creating the new database you can  Set the authorizations for the system users  Create Tables  Create Views  Create Trigger

29 SSMS Creating tables  You can create new tables using  The GUI wizard (similar to Access)  Choose the name of the fields  Set the type of the fields  Set possible constraints (“allow nulls”)  Define the primary key  Define possible foreign keys  A SQL script  Allows batch processing

30 DEMO USING SSMS

31 Database Maintenance

32  You can perform backup operations using.  SQL Server Management Studio  Transact-SQL statment

33 Backup and Recovery  Backup determines how a copy of the databases or transaction logs is made and which media are used for this process.  SQL server provides static and dynamic backups. Dynamic backup means that a database backup can be performed while users are working on data.

34 SQL Server provides four different backup methods:  Full database backup  Differential database backup  Transaction log backup  Database file (or filegroup) backup

35 Full Database Backup  Captures the state of the database at the time the backup started.  During the full database backup, the system copies the data as well as the schema of all tables of the database and the corresponding file structures.  (all uncommitted transactions in the transaction log are written to the backup media)

36 Differential Backup  As the name implies, only the parts of the database that have changed since the last full database backup are read and then written to the copy.

37 Transaction Log Backup  This backup considers only the changes recorded in the log. For example logical operations that is, change executed using the DML statements INSERT, UPDATE, and DELETE.

38 Backup Using T-SQL Statement  BACKUP DATABASE  BACKUP LOG BACKUP DATABASE {db_name} TO device_list

39 Restoring Using T-SQL Statement Manual Recovery  RESTORE LABELONLY  RESTORE HEADERONLY  RESTORE FILELISTONLY  RESTORE VERIFYONLY

40

41

42

43 DEMO WITH SSMS  BACKUP DEMO  ATTACH & DETACH

44 QUESTIONS  MSDN Virtual Labs /default.aspx