MS SQL - Database Programming

30 266 0
Tài liệu đã được kiểm tra trùng lặp
MS SQL - Database Programming

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

MS SQL Server MS SQL Server DATABASE PROGRAMMING DATABASE PROGRAMMING Index Index Session 1: Database Management Session 2: Database Normalisation Session 3: Joins & View Session 4: Stored Procedure, Union & SubQuery Session 5: SQL Operator & Functions Session 6: Trigger & Curror Appendex: MS SQL Administrator SQL Server Overview SQL Server Overview What Can SQL do? What Can SQL do?  Execute queries against a database  Retrieve data from a database  Insert records in a database  Updata records in a database  Delete records in a database  Create new databases  Create new tables in database  Create stored procedures in a database  Create views in a database  Set permissions on tables, procedures, and views Index Index Session 1: Database Management Session 1: Database Management Session 2: Database Normalisation Session 3: Joins & View Session 4: Stored Procedure, Union & SubQuery Session 5: SQL Operator & Functions Session 6: Trigger & Curror Appendex: MS SQL Administrator 1. Creating Databases  The SQL Server Management Studio (SSMS) graphical user interface can be used to create and configure new databases. 1. Creating Databases (Continue)  Using CREATE DATABASE command • Almost all the possible arguments to the CREATE DATABASE command have default values so that it's possible to create a database using a simple form of CREATE DATABASE: CREATE DATABASE <Database Name> • Other default values apply to the new database and its files. If the LOG ON clause is not specified, but data files are specified, a log file will be automatically created with a size that is 25 percent of the sum of the sizes of all data files. • For the files, if the MAXSIZE clause isn't specified, the file will grow until the disk is full. (In other words, the file size is considered unlimited.) Both SIZE and MAXSIZE can be specified in units of MB (the default) or KB. A value of 0 for FILEGROWTH indicates no growth. The default value is 10 percent, and the minimum value is 64 KB. 1. Creating Databases (Continue)  CREATE DATABASE Example CREATE DATABASE Archive ON PRIMARY ( NAME = Arch1, FILENAME = 'c:\mssql7\data\archdat1.mdf', SIZE = 100MB, MAXSIZE = 200, FILEGROWTH = 20), ( NAME = Arch2, FILENAME = 'c:\mssql7\data\archdat2.ndf', SIZE = 100MB, MAXSIZE = 200, FILEGROWTH = 20), LOG ON ( NAME = Archlog1, FILENAME = 'c:\mssql7\data\archlog1.ldf', SIZE = 100MB, MAXSIZE = 200, FILEGROWTH = 20) 2. Creating Tables  What is a Tables The tables is the most important part of a relational database. Tables are the storage location for all information within a database. Each table holds a single set of structured informatinon.  Columns and Rows A table is organised into columns and rows. One named column is defined in a table for each individual piece of data that may be stored  Types of Data In SQL Server, each column, local variable, expression, and parameter has a related data type. A data type is an attribute that specifies the type of data that the object can hold: integer data, character data, monetary data, date and time data, binary strings . 2. Creating Tables (Continue) o The simplest way to use the CREATE TABLE command is to provide a table name and a comma-separated list of column specifications. This is shown in the syntax below: CREATE TABLE table-name ( column-specification1, column-specification2, . column-specificationN ) o Each column specification describes a column that will be created within the table. Here we can provide a name for the column and specify the column type and size to use. 2. Creating Tables (Continue) o We can also determine if the column should permit the storage of null values by appending either "NULL" or "NOT NULL" to the specification. These three items are separated by space characters, making the syntax for a column specification as follows: column-name data-type [NULL | NOT NULL] The use of "NULL" is optional. If omitted, a column will be nullable by default. [...]... CreatedDate BETWEEN '200 7-1 2-0 8' AND '200 8-0 1-1 5' 4.T -SQL Queries (Continue)  Comparing Values Against a List Sometimes you will want to determine if a value matches an item from a list This is possible using the IN clause and a comma -separated list of values in parentheses Example SELECT DISTINCT EngineerId FROM EngineerWorkingAreas WHERE AreaCode IN ('HUM', 'NYO', 'SYO' , 'WYO') 4.T -SQL Queries (Continue)... WHERE LastName LIKE ‘[R-D]ita’ 4.T -SQL Queries (Continue) + The list or range of values can also be negated using a caret symbol (^) or (!) In this case, the wildcard specifies that the character at the given position must not be within the stated list or range Example SELECT * FROM Persons WHERE LastName LIKE ‘[!bsp]%’ Or SELECT * FROM Persons WHERE LastName LIKE ‘[^D-R]%’ 4.T -SQL Queries (Continue)... operand is less than the second . MS SQL Server MS SQL Server DATABASE PROGRAMMING DATABASE PROGRAMMING Index Index Session 1: Database Management Session 2: Database Normalisation. Session 5: SQL Operator & Functions Session 6: Trigger & Curror Appendex: MS SQL Administrator SQL Server Overview SQL Server Overview What Can SQL do?

Ngày đăng: 28/10/2013, 03:15

Tài liệu cùng người dùng

Tài liệu liên quan