|
| 1 | +DROP TABLE Doctor |
| 2 | +GO |
| 3 | +DROP TABLE Patient |
| 4 | +GO |
| 5 | +DROP TABLE Person |
| 6 | +GO |
| 7 | +CREATE TABLE Person( |
| 8 | + PersonID INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY NOT NULL, |
| 9 | + FirstName NVARCHAR(50) NOT NULL, |
| 10 | + LastName NVARCHAR(50) NOT NULL, |
| 11 | + MiddleName NVARCHAR(50) , |
| 12 | + Gender NCHAR(1) NOT NULL |
| 13 | +) |
| 14 | +GO |
| 15 | +INSERT INTO Person (FirstName, LastName, Gender) VALUES ('John', 'Pupkin', 'M') |
| 16 | +GO |
| 17 | +INSERT INTO Person (FirstName, LastName, Gender) VALUES ('Tester', 'Testerson', 'M') |
| 18 | +GO |
| 19 | +INSERT INTO Person (FirstName, LastName, Gender) VALUES ( 'Miss', 'Scarlet', 'F') |
| 20 | +GO |
| 21 | +INSERT INTO Person (FirstName, LastName, Gender) VALUES ('Rev', 'Green', 'M') |
| 22 | +GO |
| 23 | +INSERT INTO Person (FirstName, LastName, Gender) VALUES ('Col', 'Mustard', 'M') |
| 24 | +GO |
| 25 | +INSERT INTO Person (FirstName, LastName, Gender) VALUES ('Mrs','Peacock', 'F') |
| 26 | +GO |
| 27 | +INSERT INTO Person (FirstName, LastName, Gender) VALUES ('Prof', 'Plum','M') |
| 28 | +GO |
| 29 | +INSERT INTO Person (FirstName, LastName, Gender) VALUES ('Mrs', 'White', 'F') |
| 30 | +GO |
| 31 | + |
| 32 | +-- Doctor Table Extension |
| 33 | + |
| 34 | +CREATE TABLE Doctor( |
| 35 | + PersonID INTEGER PRIMARY KEY NOT NULL, |
| 36 | + Taxonomy VARCHAR(50) NOT NULL, |
| 37 | + FOREIGN KEY FK_Doctor_Person(PersonID) REFERENCES Person |
| 38 | +) |
| 39 | +GO |
| 40 | +INSERT INTO Doctor (PersonID, Taxonomy) VALUES (1, 'Psychiatry') |
| 41 | +GO |
| 42 | + |
| 43 | +DROP TABLE MasterTable |
| 44 | +GO |
| 45 | +DROP TABLE SlaveTable |
| 46 | +GO |
| 47 | +CREATE TABLE MasterTable( |
| 48 | + ID1 INTEGER NOT NULL, |
| 49 | + ID2 INTEGER NOT NULL, |
| 50 | + PRIMARY KEY (ID1,ID2) |
| 51 | +) |
| 52 | +GO |
| 53 | +CREATE TABLE SlaveTable( |
| 54 | + ID1 INTEGER NOT NULL, |
| 55 | + ID2222222222222222222222 INTEGER NOT NULL, |
| 56 | + ID2222222222222222 INTEGER NOT NULL, |
| 57 | + FOREIGN KEY FK_SlaveTable_MasterTable (ID2222222222222222222222, ID1) |
| 58 | + REFERENCES MasterTable |
| 59 | +) |
| 60 | +GO |
| 61 | + |
| 62 | +CREATE TABLE Patient |
| 63 | +( |
| 64 | + PersonID INTEGER PRIMARY KEY NOT NULL, |
| 65 | + Diagnosis VARCHAR(256) NOT NULL, |
| 66 | + |
| 67 | + FOREIGN KEY FK_Patient_Person (PersonID) REFERENCES Person |
| 68 | +) |
| 69 | +GO |
| 70 | +INSERT INTO Patient(PersonID, Diagnosis) VALUES (2, 'Hallucination with Paranoid Bugs'' Delirium of Persecution') |
| 71 | +GO |
| 72 | +DROP TABLE Parent |
| 73 | +GO |
| 74 | +DROP TABLE Child |
| 75 | +GO |
| 76 | +DROP TABLE GrandChild |
| 77 | +GO |
| 78 | +CREATE TABLE Parent (ParentID int, Value1 int) |
| 79 | +GO |
| 80 | +CREATE TABLE Child (ParentID int, ChildID int) |
| 81 | +GO |
| 82 | +CREATE TABLE GrandChild (ParentID int, ChildID int, GrandChildID int) |
| 83 | +GO |
| 84 | +DROP TABLE LinqDataTypes |
| 85 | +GO |
| 86 | +CREATE TABLE LinqDataTypes( |
| 87 | + ID int, |
| 88 | + MoneyValue decimal(10,4), |
| 89 | + DateTimeValue timestamp, |
| 90 | + DateTimeValue2 timestamp Default NULL, |
| 91 | + BoolValue smallint, |
| 92 | + GuidValue varchar(38), |
| 93 | + BinaryValue blob(5000) Default NULL, |
| 94 | + SmallIntValue smallint, |
| 95 | + IntValue int Default NULL, |
| 96 | + BigIntValue bigint Default NULL, |
| 97 | + StringValue VARCHAR(50) Default NULL |
| 98 | +) |
| 99 | +GO |
| 100 | +DROP TABLE TestIdentity |
| 101 | +GO |
| 102 | +CREATE TABLE TestIdentity ( |
| 103 | + ID INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY NOT NULL |
| 104 | +) |
| 105 | +GO |
| 106 | +DROP TABLE AllTypes |
| 107 | +GO |
| 108 | +CREATE TABLE AllTypes( |
| 109 | + ID INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY NOT NULL |
| 110 | + |
| 111 | + , bigintDataType bigint Default NULL |
| 112 | + , binaryDataType binary(20) Default NULL |
| 113 | + , blobDataType blob Default NULL |
| 114 | + , charDataType char(1) Default NULL |
| 115 | + , CharForBitDataType char(5) for bit data Default NULL |
| 116 | + , clobDataType clob Default NULL |
| 117 | + , dataLinkDataType dataLink Default NULL |
| 118 | + , dateDataType date Default NULL |
| 119 | + , dbclobDataType dbclob(100) CCSID 1200 Default NULL |
| 120 | + , decfloat16DataType decfloat(16) Default NULL |
| 121 | + , decfloat34DataType decfloat(34) Default NULL |
| 122 | + , decimalDataType decimal(30) Default NULL |
| 123 | + , doubleDataType double Default NULL |
| 124 | + , graphicDataType graphic(10) ccsid 13488 Default NULL |
| 125 | + , intDataType int Default NULL |
| 126 | + , numericDataType numeric Default NULL |
| 127 | + , realDataType real Default NULL |
| 128 | + , rowIdDataType rowId |
| 129 | + , smallintDataType smallint Default NULL |
| 130 | + , timeDataType time Default NULL |
| 131 | + , timestampDataType timestamp Default NULL |
| 132 | + , varbinaryDataType varbinary(20) Default NULL |
| 133 | + , varcharDataType varchar(20) Default NULL |
| 134 | + , varCharForBitDataType varchar(5) for bit data Default NULL |
| 135 | + , varGraphicDataType vargraphic(10) ccsid 13488 Default NULL |
| 136 | + , xmlDataType xml Default NULL |
| 137 | +) |
| 138 | +GO |
| 139 | + |
| 140 | +INSERT INTO AllTypes (bigintDataType) VALUES (NULL) |
| 141 | + |
| 142 | +GO |
| 143 | +INSERT INTO AllTypes( |
| 144 | + bigintDataType |
| 145 | + , binaryDataType |
| 146 | + , blobDataType |
| 147 | + , charDataType |
| 148 | + , CharForBitDataType |
| 149 | + , clobDataType |
| 150 | + , dataLinkDataType |
| 151 | + , dateDataType |
| 152 | + , dbclobDataType |
| 153 | + , decfloat16DataType |
| 154 | + , decfloat34DataType |
| 155 | + , decimalDataType |
| 156 | + , doubleDataType |
| 157 | + , graphicDataType |
| 158 | + , intDataType |
| 159 | + , numericDataType |
| 160 | + , realDataType |
| 161 | + , rowIdDataType |
| 162 | + , smallintDataType |
| 163 | + , timeDataType |
| 164 | + , timestampDataType |
| 165 | + , varbinaryDataType |
| 166 | + , varcharDataType |
| 167 | + , varCharForBitDataType |
| 168 | + , varGraphicDataType |
| 169 | + , xmlDataType |
| 170 | +) VALUES ( |
| 171 | + 1000000 --bigIntDataType |
| 172 | + , Cast('123' as binary) --binaryDataType |
| 173 | + , Cast('234' as blob) --blobDataType |
| 174 | + , 'Y' --charDataType |
| 175 | + , '123' --CharForBitDataType |
| 176 | + , Cast('567' as clob) --clobDataType |
| 177 | + , DEFAULT --dataLinkDataType |
| 178 | + , '2012-12-12' --dateDataType |
| 179 | + , Cast('890' as dbclob) --dbclobDataType |
| 180 | + , 888.456 --decfloat16DataType |
| 181 | + , 777.987 --decfloat34DataType |
| 182 | + , 666.987 --decimalDataType |
| 183 | + , 555.987 --doubleDataType |
| 184 | + , 'graphic' -- DEFAULT --Cast('graphic' as graphic) --graphicDataType gets error when casting the data |
| 185 | + , 444444 --intDataType |
| 186 | + , 333.987 --numericDataType |
| 187 | + , 222.987 --realDataType |
| 188 | + , DEFAULT --rowIdDataType |
| 189 | + , 100 --smallintDataType |
| 190 | + , '12:12:12' --timeDataType |
| 191 | + , '2012-12-12 12:12:12' --timestampDataType |
| 192 | + , Cast('456' as binary) --varbinaryDataType |
| 193 | + , 'var-char' --varcharDataType |
| 194 | + , 'vcfb' --varCharForBitDataType |
| 195 | + , 'vargraphic' --varGraphicDataType |
| 196 | + , '<root><element strattr="strvalue" intattr="12345"/></root>' --xmlDataType |
| 197 | +) |
| 198 | +GO |
| 199 | + |
| 200 | +DROP VIEW PersonView |
| 201 | +GO |
| 202 | +CREATE VIEW PersonView |
| 203 | +AS |
| 204 | +SELECT * FROM Person |
| 205 | +GO |
| 206 | +DROP Procedure Person_SelectByKey |
| 207 | +GO |
| 208 | +CREATE Procedure Person_SelectByKey(in ID integer) |
| 209 | +RESULT SETS 1 |
| 210 | +LANGUAGE SQL |
| 211 | +BEGIN |
| 212 | + DECLARE C1 CURSOR FOR |
| 213 | + SELECT * FROM Person WHERE PersonID = ID; |
| 214 | + |
| 215 | + OPEN C1; |
| 216 | +END |
| 217 | +GO |
0 commit comments