SQL 學習筆記 ( )

2021-05-08 21:43:38 字數 1139 閱讀 9934

sql 語法特點:

1 每個語句以;結束,中間用()包含,,間隔。

2 對變數和常量等需要用()包含。

3 關鍵字大寫,變數名首大寫字母用表名表徵,然後用小寫表徵屬性

基本語句: 

desc 表名

檢視表詳細屬性

建表: create table 表名

( 屬性名 型別(約束)  主鍵(primary key)

如果是域為主鍵 primary key(屬性...屬性),

foregin key (屬性a) references 表名b(屬性c)

//a被b種的c屬性引用為主鍵。

//?主碼這麼表示)

插入資料:錶可選,{}表任意多

insert into table

[(column )]     *1

values

(columnvalue );

如果預設 *1,則value對應填入表中,否則按照屬性填入,預設的資料為null,主鍵不能為null

選擇資料:選擇資料是乙個建立新錶的過程

select [distinct]

(column [ ] )| *

from table [ ]

[order by column [asc] | [desc

[ ] ]

where predicate [ ];

列名可以用*來預設選所有列

distinct 用來消除相同元組

order by  按順序生成新標,asc為遞增,desc為遞減。

where給出條件限制, and 表示且,or表示或,not表示否

null為非確定值,不參與比較,用is null和is not null判斷

更新資料

update table

set column = value

[ where predicate [ ]];

刪除資料:

delete from table

[where predicate [ ] ];

sql學習筆記

declare rc int declare stattime datetime declare endtime datetime select stattime 2008 06 22 00 00 00.000 select endtime 2008 06 22 01 00 00.000 while...

SQL學習筆記

一 資料庫的建立與刪除 create database demo drop database demo 二 表的定義與更改 1 表的定義 建立乙個學生情況表student create table student st class char 8 st no char 10 not null,st n...

SQL學習筆記

select from select from table t where t.no 條件 order by t.iddesc c where rownum 1 insert into ri i inform select seq ri i inform.nextval,t.ced quote no...