CIS 282 Final Review
Upcoming SlideShare
Loading in...5
×
 

CIS 282 Final Review

on

  • 813 views

 

Statistics

Views

Total Views
813
Slideshare-icon Views on SlideShare
755
Embed Views
58

Actions

Likes
0
Downloads
23
Comments
0

1 Embed 58

http://rriness.spscc.edu 58

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    CIS 282 Final Review CIS 282 Final Review Presentation Transcript

    • CIS-282
    • Database Server  Operates as a separate “process”  Need to communicate with the server using a separate application  Connection required to transmit request and response  Management Studio and SQL Server are different programs
    • Managing SQL Server  Management Studio gives access to most functions/operations  Query window provides method to write/execute T- SQL statements  “T” = transact  SQL Service Manager provides way to start/stop Server
    • SQL Server Databases  Two files are maintained  Data file (.mdf)  Transaction Log file (.ldf)  Files can be spread over multiple machines  Always need a primary file group
    • Database Contents  Tables  User tables hold data  System tables hold data about the database  Stored Procedures, User Defined Functions  Views  Indexes
    • Default Databases  Master: Logins/User roles; system configuration; names/locations of databases; SQL Server startup  Tempdb: Lasts duration of SQL Server session; temporary holding space  Model: Sets characteristics of new databases  MSDB: Holds information about jobs SQL Server Agent runs
    • Security  Windows Authentication: Windows network logins used  Mixed-mode: Windows OR SQL Server logins used  Login: To access server  User: To access a database  Network security trumps all….
    • Roles  Server – administrative functions  Task based:  Backup  Create database  Roles are fixed  Database/Application – groups of users with common activities  Read/write all data  Read/write select data  Read data only
    • Normalization  Process for reducing duplicate and redundant data  1st Normal Form: eliminate repeating groups  2nd Normal Form: each column in a table depends on the primary key  can’t get information with only part of the key  3rd Normal Form: A column cannot be dependent on another column that isn’t the primary key
    • Relationships  Types  One-to-one  One-to-many  Many-to-many  Requires a primary key on the ‘one’ side, foreign key on the ‘many’ side  Referential Integrity defines how values work across tables
    • Table Definition  Fields need a name and datatype  SQL Server datatypes are different from Access and procedural programming language datatypes  Fieldnames can include spaces – but poor practice  Identity – create unique number for each row
    • Constraints  Allow Null – value not required to add record  Check Constraints – test field or row values  Default value – if no data is entered into a field  Unique – values must be different for each row
    • Database Diagrams  Illustrate database design  Add, modify tables, indexes, relationships  Can control view, table details
    • Indexes  Help to select and find records  Serve as a “cross-reference”  Can be based on one or more fields
    • Good Index Characteristics  Low maintenance columns  Includes columns used frequently in Where or Order By clauses  Don’t have to go out to table for data  Help search for ranges of records
    • Action Queries  Insert: insert into tablename(fieldlist) values(valuelist)  Update: update tablename set field1=value1, field2=value2  Delete: delete from tablename [where condition]
    • Select Statement  Can use an alias for fields and/or tables  Select fields  From table  Join table On field=field  Inner – both tables have records with matching values  Outer – all records from one table and any matches found in second table
    • Where  Conditions to determine records returned  Multiple conditions require And … Or  Can use where clause to implement join between tables  Sub-queries allow tables to be limited by values in a second table without using a join
    • Views  Pre-defined select statement  Used like a virtual table SELECT * FROM v_CurrentEmployees
    • View Performance  By default views run just as a query processed from command line  Adds second step to execution:  select from view  execute view itself  Can add an index to speed execution  Specific requirements when creating an index on a view
    • Declaring & Using Variables  Use Declare  Must use Set or Select to assign  Variables are local to a procedure
    • System Variables  @@ identifies system variables  Value of a system variable can change  @@Rowcount changes with next select, update, insert or delete  @@Error changes with each instruction  @@Identity changes with next insert
    • Decision-making  IF … ELSE  No end if  Need to use Begin/End if have more than one instruction to execute IF StartDate < EndDate Begin … End ELSE
    • Simple Case Statement  CASE  Similar to SELECT CASE  Compares one value to different cases CASE Category WHEN ‘pop_comp’ THEN ‘Popular Computing’ WHEN ‘mod_cook’ THEN ‘Modern Cooking’ END
    • Searched Case  No test expression  Each WHEN has a boolean test CASE WHEN Points >= 90 THEN ‘A’ WHEN Points < 90 AND Extra > 0 THEN ‘A’ END
    • Errors  Errors can occur because of SQL statement  Invalid syntax, or data type  Errors can also reflect business rules  Data doesn’t match requirements
    • Try/Catch  Similar to .Net languages  Need to include BEGIN/END BEGIN TRY <code> END TRY BEGIN CATCH <error handling code> END CATCH
    • BATCH  Batch is a logical group of SQL statements  Run-time error will halt execution only of FURTHER steps  Can break up multiple steps using GO  Not available in all tools  GO causes editing tool to send statements to that point for execution  GO isn’t sent to SQL Server
    • Stored Procedures  “Code” written in Structured Query Language  Different from a Script  Script is a text file that is run  Sproc is compiled and stored in the database
    • Using Stored Procedures  Use Execute to call  Procedures generate a return value  Return value is about success of execution  Exec spName(parameters) doesn’t capture the return value  Exec @Variable = spName(parameters) captures return value
    • Parameters  Can use any SQL data type or User Defined Data Types  Input: Values sent into the stored procedure  Required unless there’s a default value  Output: Values sent to the calling routine  Output parameter is different than return value!  Must be specified as output; default is an input parameter
    • Writing Stored Procedures  Make modular  Use RaisError to send a message  Message can be a string or refer to a message number  User-defined messages start at 50001 and are stored on server – not in database!
    • User-defined Functions  Similar to stored procedures, but  Aren’t executed (no EXEC)  Can be run “in-line” (as part of another SQL statement)  Return a value (scalar) or table, don’t have a “return value” or output parameters
    • Triggers  Typically used to enforce rules, log activity, or maintain data (archive)  Similar to a stored procedure  Respond to actions on a table  Trigger is not called  Trigger is specific to a table  Table can have multiple triggers  One trigger can respond to different actions
    • Triggers & Constraints  Constraints give better performance  Triggers can span tables, databases, servers; constraints are table specific  If testing a value inserted in one table depends on an entry in another table, use a trigger  If testing a value depends on an entry in the current row, a relationship, or function result, use a constraint
    • Types of Triggers  FOR/AFTER execute after data has been written to tables  Constraints have already been satisfied  INSTEAD OF executes before changes are written  Trigger must complete requested action if appropriate
    • Update()  Can test if a column has changed  Update(columnname) If Update(FirstName) Print ‘FirstName has changed’
    • Transactions  Provides method for canceling an operation  Can restore rows, columns to original state in event of error or business logic failure  Use when changes will either be committed or discarded in entirety  Begin Tran: Identifies the start  Commit Tran: Write changes  Rollback Tran: Cancel changes
    • ACID  Atomicity: All of the changes will be accepted or none of the changes will be accepted  Consistency: Data is either in its original or changed state  Isolation: If multiple transactions occur, data is never available in an intermediate state  Durability: Once finished, all changes are complete and changes can only be done by another transaction/unit of work
    • Locking & Concurrency  Locking prevents other operations from changing that data  Concurrency refers to multiple actions running against database at the same time  What happens if you want to change data I’m working with?