Giáo trình SQL bài 3

40 184 0
Giáo trình SQL bài 3

Đ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

Lab 01b Data Types – DDL – DML Outlines Data types DDL Create table Alter table Drop table DML Insert Update Delete Faculty of Science and Technology Database Fundamentals Data types (1) Integer Name bigint int smallint tinyint Bytes Range -263 (-9,223,372,036,854,775,808) to 263 - (9,223,372,036,854,775,807) -231 (-2,147,483,648) to 231 - (2,147,483,647) -215 (-32,768) to 215 - (32,767) Faculty of Science and Technology to 255 Database Fundamentals Data types (2) Exact numeric Name Bytes Range decimal[p[,s]] – 17 - 1038 +1 to 1038 - numeric[p[,s]] – 17 - 1038 +1 to 1038 - p (precision) The maximum total number of decimal digits that can be stored, both to the left and to the right of the decimal point The precision must be a value from through the maximum precision of 38 The default precision is 18 s (scale) The maximum number of decimal digits that can be stored to the right of the decimal point Scale must be a value from through p Scale can be specified only if precision is specified The default scale is 0; therefore, [...]... 'M', 30 000, '33 3445555', 5) GO INSERT INTO Employee VALUES ('Alicia', 'J', 'Zelaya', '999887777', '19-JUL-1958', 'Spring,TX', 'F', 25000, '98765 432 1', 4) GO INSERT INTO Employee VALUES ('Ramesh', 'K', 'Narayan', '666884444', '15-SEP-1952', 'Humble,TX', 'M', 38 000, '33 3445555', 5) GO INSERT INTO Employee VALUES ('Joyce', 'A', 'English', '4 534 534 53' , '31 -JUL-1962', 'Houston, TX', 'F', 25000, '33 3445555',... ('Franklin', 'T', 'Wong', '33 3445555', '08-DEC-1945', 'Houston,TX', 'M', 40000, '888665555', null, 5) GO INSERT INTO Employee VALUES ('Jennifer', 'S', 'Wallace', '98765 432 1', '20-JUN-1 931 ', 'Bellaire,TX', 'F', 430 00, '888665555', null, 4) GO … Faculty of Science and Technology Database Fundamentals 34 Practice: Insert Data (3) Employee INSERT INTO Employee VALUES ('John', 'B', 'Smith', '1 234 56789', '09-Jan-1955',... 'Houston,TX', 'M', 25000, '98765 432 1', 4) GO Faculty of Science and Technology Database Fundamentals 35 Practice: Update date Employee UPDATE Department SET MgrSsn = '33 3445555' WHERE DNumber = 5 GO UPDATE Employee SET MgrSsn = '98765 432 1' WHERE DNumber = 4 GO UPDATE Employee SET MgrSsn = '888665555' Faculty of Science and Technology WHERE DNumber =Database 1 Fundamentals 36 ... ] Example Update Department Set MgrSSN = '33 3445555‘ Where DNumber = 5; Faculty of Science and Technology Database Fundamentals 26 Delete Delete from table_name [Where ] Example Delete from Department; Or Delete from Department Where DNumber = 5; Faculty of Science and Technology Database Fundamentals 27 Practice Create Database company ( 13 th slide) Create Tables: Department – Employee... ] [ ; ] Example: Drop table Department Faculty of Science and Technology Database Fundamentals 23 DML Insert Update Delete Faculty of Science and Technology Database Fundamentals 24 Insert Insert into table_name [(column_list)] Values (value_list) Example INSERT INTO Department VALUES (5, 'Research', '33 3445555', '22-MAY-78'); Or INSERT INTO Department (DNumber, DName) VALUES (5, 'Research'); Faculty... Science and Technology Database Fundamentals 32 Practice: Insert Data (1) Department INSERT INTO Department VALUES ('Research', 5, Null, '22-MAY-1978') GO INSERT INTO Department VALUES ('Administration', 4, Null, '01-JAN-1985') GO INSERT INTO Department VALUES ('Headquarters', 1, Null, '19-JUN-1971') GO Faculty of Science and Technology Database Fundamentals 33 Practice: Insert Data (2) Employee INSERT... NOT NULL, MInit varchar(1) NULL, LName varchar(15) NOT NULL, SSN char(9) NOT NULL, BDate datetime NULL, Address varchar (30 ) NULL, Sex char(1) NULL, Salary numeric(10, 2) NULL, SuperSSN char(9) NULL, DNo numeric(4, 0) NULL) GO Faculty of Science and Technology Database Fundamentals 30 Practice: Create Primary Key Department ALTER TABLE Department ADD Constraint pk_Dept PRIMARY KEY (DNumber) GO Employee... Faculty of Science and Technology Database Fundamentals 11 Data types (10) Special Name bit cursor timestamp sysname table Bytes Range 1 1 byte for every 8 bit columns 0-8 8 one column per table 256 - sql_ variant 0-8016 Faculty of Science and Technology Database Fundamentals 12 Database CREATE DATABASE Company ON PRIMARY ( NAME = 'Company', FILENAME = 'C:\DATA\Company.mdf' , SIZE = 2048KB , MAXSIZE... ( NAME = 'Company_log', FILENAME = 'C:\DATA\Company_log.ldf' , SIZE = 1024KB , MAXSIZE = 2048KB , FILEGROWTH = 10%) GO DROP DATABASE Company GO Faculty of Science and Technology Database Fundamentals 13 DDL Create table Alter table Drop table Faculty of Science and Technology Database Fundamentals 14 Create Table (1) CREATE TABLE table_name ( [ ] [ , n ] ) [;]... CASCADE | SET NULL | SET DEFAULT } ] [ ON UPDATE { NO ACTION | CASCADE | SET NULL | SET DEFAULT } ] | CHECK ( logical_expression ) } Faculty of Science and Technology Database Fundamentals 16 Create table (3) < table_constraint > ::= [ CONSTRAINT constraint_name ] { { PRIMARY KEY | UNIQUE } [ CLUSTERED | NONCLUSTERED ] (column [ ASC | DESC ] [ , n ] ) | FOREIGN KEY ( column [ , n ] ) REFERENCES referenced_table_name ... smallint tinyint Bytes Range -2 63 (-9,2 23, 372, 036 ,854,775,808) to 2 63 - (9,2 23, 372, 036 ,854,775,807) - 231 (-2,147,4 83, 648) to 231 - (2,147,4 83, 647) -215 ( -32 ,768) to 215 - (32 ,767) Faculty of Science... Data types (3) Appropiate numeric Name Float[(n)] real Bytes Range n - 1.79E +30 8 to -2.23E -30 8, and 2.23E -30 8 to 1.79E +30 8 - 3. 40E + 38 to -1.18E - 38 , and 1.18E - 38 to 3. 40E + 38 Faculty of... Data types (4) Monetary Name Money Bytes Range -922 ,33 7,2 03, 685,477.5808 to 922 ,33 7,2 03, 685,477.5807 smallmoney - 214,748 .36 48 to 214,748 .36 47 Faculty of Science and Technology Database Fundamentals

Ngày đăng: 03/12/2015, 03:50

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

  • Đang cập nhật ...

Tài liệu liên quan