1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344
| create database EN_learning; use EN_learning; ALTER DATABASE EN_learning COLLATE Chinese_PRC_CI_AS create table Admin ( admin_id char(10) primary key, admin_passwd varchar(16) )
create table users ( user_id char(10) primary key, user_passwd varchar(16), user_name varchar(20), user_date date default(getdate()), user_learn smallint default(0) )
create table en_list ( word char(40) primary key, symbol nvarchar(max), trans nvarchar(max), frequency int default(0), img image, vocal image ) create table motto ( sentence nvarchar(max), trans nvarchar(max) ) create table jp_list ( word nvarchar(80) primary key , symbol nvarchar(80), trans nvarchar(max), frequency int default(0), img image, vocal image )
create trigger users_add on users after insert as declare @user_id varchar(10), @create_table varchar(300), @create_view varchar(300), @sel varchar(300) select @user_id=user_id from inserted set @create_table='create table user_'+@user_id+ ' (' + ' rank smallint default(0), word char(40) primary key, symbol nvarchar(max), trans nvarchar(max), add_date date default(getdate()), del_date date )' exec(@create_table)
set @sel='select rank,word,symbol,trans,add_date' + ' from user_'+@user_id+' where rank>=0' set @create_view='create view user_1_'+@user_id+' as '+@sel exec (@create_view)
set @sel='select word,symbol,trans,add_date,del_date' + ' from user_'+@user_id+' where rank<0' set @create_view='create view user_2_'+@user_id+' as '+@sel exec (@create_view) go
insert into users(user_id, user_passwd, user_name) values ('1001001001','123','test') insert into users(user_id, user_passwd, user_name) values ('1001001002','123','test2')
create trigger users_del on users after delete as declare @user_id char(10), @drop_table varchar(100), @drop_view varchar(100) select @user_id=user_id from deleted set @drop_table='drop table user_'+@user_id exec (@drop_table)
set @drop_view='drop view user_1_'+@user_id exec (@drop_view)
set @drop_view='drop view user_2_'+@user_id exec (@drop_view) go
delete from users where user_id='1001001001' delete from users where user_id='1001001002'
create proc en_list_counter as select count(*) from en_list go
exec en_list_counter
create proc EN_search @word varchar(40) as set @word='%'+@word+'%' select * from en_list where word like @word declare @w varchar(40), @frequency int declare csr cursor for select word,frequency from en_list where word like @word open csr fetch next from csr into @w,@frequency while @@FETCH_STATUS=0 begin update en_list set frequency=@frequency+1 where word=@w fetch next from csr into @w,@frequency end close csr deallocate csr go
exec EN_search 'cat'
create proc CH_search @trans varchar(40) as declare @w char(40), @frequency int set @trans='%'+@trans+'%' select * from en_list where trans like @trans
declare csr cursor for select word,frequency from en_list where trans like @trans open csr fetch next from csr into @w,@frequency while @@FETCH_STATUS=0 begin update en_list set frequency=@frequency+1 where word=@w fetch next from csr into @w,@frequency end close csr deallocate csr go
exec CH_search '好' exec CH_search 'prep'
create proc order_en_list_fre @order varchar(10) as if(@order='ASC') begin select * from en_list order by frequency asc end else if(@order='DESC') begin select * from en_list order by frequency desc end go
exec order_en_list_fre 'ASC' exec order_en_list_fre 'DESC'
create proc en_list_to_user @user_id varchar(10),@word varchar(40) as declare @ins nvarchar(max) set @ins='insert into user_'+@user_id+'(word,symbol,trans)' + 'select word,symbol,trans from en_list where word='''+@word+'''' exec(@ins) go
exec en_list_to_user '1001001001','accomplished'
create proc day_en_word @user_id varchar(20),@num smallint,@val smallint as declare @word varchar(40), @csr varchar(300) if(@val=1) begin set @csr='declare csr cursor for ' + 'select top '+convert(char,@num)+' word from en_list ' + 'where word not in(select word from user_'+@user_id+')' + 'order by word asc' end else if(@val=2) begin set @csr='declare csr cursor for ' + 'select top '+convert(char,@num)+' word from en_list ' + 'where word not in(select word from user_'+@user_id+')' + 'order by word desc' end else if(@val=3) begin set @csr='declare csr cursor for ' + 'select top '+convert(char,@num)+' word from en_list ' + 'where word not in(select word from user_'+@user_id+')' + 'order by frequency desc' end else if(@val=4) begin set @csr='declare csr cursor for ' + 'select top '+convert(char,@num)+' word from en_list ' + 'where word not in(select word from user_'+@user_id+')' + 'order by newid()' end exec (@csr) open csr fetch next from csr into @word while @@FETCH_STATUS=0 begin exec en_list_to_user @user_id,@word fetch next from csr into @word end close csr deallocate csr go
exec day_en_word '1001001001',10,1 exec day_en_word '1001001001',10,4
create proc rank_up @user_id varchar(10),@word varchar(40) as declare @update varchar(100) set @update='update user_'+@user_id+' set rank=rank+1 where word='''+@word+'''' exec(@update) go
exec rank_up '1001001001','a' exec rank_up '1001001001','above'
create proc rank_down @user_id varchar(10),@word varchar(40) as declare @update varchar(100) set @update='update user_'+@user_id+' set rank=rank-1 where word='''+@word+'''' exec(@update) go exec rank_down '1001001001','a'
create proc rank_move @user_id varchar(10),@word varchar(40) as declare @update varchar(100) set @update='update user_'+@user_id+' set rank=-1,del_date=getdate() where word='''+@word+'''' exec(@update) go exec rank_move '1001001001','accomplished'
create proc order_user1_rank @user_id varchar(10),@order varchar(10) as declare @sel varchar(100) if(@order='ASC') begin set @sel='select * from user_1_'+@user_id+' order by rank asc' end else if(@order='DESC') begin set @sel='select * from user_1_'+@user_id+' order by rank desc' end exec(@sel) go
exec order_user1_rank '1001001001','desc'
create proc order_user1_date @user_id varchar(10),@order varchar(10) as declare @sel varchar(100) if(@order='ASC') begin set @sel='select * from user_1_'+@user_id+' order by add_date asc' end else if(@order='DESC') begin set @sel='select * from user_1_'+@user_id+' order by add_date desc' end exec(@sel) go
exec order_user1_date '1001001001','desc'
create proc day_learn @user_id varchar(10) as update users set user_learn=user_learn+1 where user_id=@user_id declare @sel varchar(100) set @sel='select word,symbol,trans from user_2_'+@user_id+' where del_date=convert(date,getdate())' exec(@sel) go
exec day_learn '1001001001'
create proc user_en_test @user_id varchar(10) as declare @sel varchar(100) set @sel='select top 10 word,symbol,trans from user_2_'+@user_id+ ' order by newid()' exec(@sel) go
exec user_en_test '1001001001'
create proc day_motto as select top 1 sentence,trans from motto order by newid() go
exec day_motto
update en_list set img=BulkColumn from openrowset(bulk N'D:\#DownLoad\2.2\数据库\img\cat.png',single_blob) as blob where word='cat' update en_list set img=BulkColumn from openrowset(bulk N'D:\#DownLoad\2.2\数据库\img\dog.png',single_blob) as blob where word='dog' update en_list set img=BulkColumn from openrowset(bulk N'D:\#DownLoad\2.2\数据库\img\amphibian.png',single_blob) as blob where word='amphibian' update en_list set img=BulkColumn from openrowset(bulk N'D:\#DownLoad\2.2\数据库\img\aback.png',single_blob) as blob where word='aback' exec EN_search 'amphibian'
update en_list set vocal=BulkColumn from openrowset(bulk N'D:\#DownLoad\2.2\数据库\vocal\aback.mp3',single_blob) as blob where word='aback' update en_list set vocal=BulkColumn from openrowset(bulk N'D:\#DownLoad\2.2\数据库\vocal\cat.mp3',single_blob) as blob where word='cat' update en_list set vocal=BulkColumn from openrowset(bulk N'D:\#DownLoad\2.2\数据库\vocal\dog.mp3',single_blob) as blob where word='dog' update en_list set vocal=BulkColumn from openrowset(bulk N'D:\#DownLoad\2.2\数据库\vocal\amphibian.mp3',single_blob) as blob where word='amphibian' exec EN_search 'dog'
|