欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

SQL語(yǔ)句基本語(yǔ)法

首先寫(xiě)入可顯示中文代碼

專(zhuān)注于為中小企業(yè)提供成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站制作服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)新疆免費(fèi)做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動(dòng)了上1000家企業(yè)的穩(wěn)健成長(zhǎng),幫助中小企業(yè)通過(guò)網(wǎng)站建設(shè)實(shí)現(xiàn)規(guī)模擴(kuò)充和轉(zhuǎn)變。

set character_set_client=gbk;
set character_set_results=gbk;

或只輸一句  

set names gbk;

創(chuàng)建數(shù)據(jù)庫(kù)

create database 庫(kù)名;

查詢(xún)現(xiàn)有數(shù)據(jù)局

show databases;

刪除數(shù)據(jù)庫(kù)

drop database +庫(kù)名

使用庫(kù)

use 庫(kù)名;

創(chuàng)建表

create table Student(
     id int,
     name varchar(20) not null,
     age int,
     sex  char(2) not null;
     major varchar(20)
);

以學(xué)生表為例,創(chuàng)建主鍵自增表

creat table student(
     id int primary key auto_increment,//注:只有int類(lèi)型且為primary key 才可以使用auto_increment.
     name varchar(20) not null,
     banji varchar(20) not null,
     banji integer default(1),  //設(shè)定默認(rèn)值為1
     );

創(chuàng)建表后添加設(shè)定或改變默認(rèn)值

例如:

alter table student modify score int;
alter table student modify score int default '1';

主鍵約束 

創(chuàng)建表時(shí)添加主鍵約束

creat table person(
    id int not null,
    name varchar(20) not null,
    adress varchar(50),
    primary key(id)
);

創(chuàng)建表后添加主鍵約束

alter table person add primary key(id);

外鍵約束

create table Score(
     p_id int,
     name varchar(20) not null,
     age int,
     sex  char(2) not null;
     major varchar(20),
     foreign key(p_id) reference persons(id)
);

創(chuàng)建表后添加外鍵約束:

alter table 表名 add foreign key (p_id) references 主表名 (id)

創(chuàng)建主外鍵關(guān)系約束

alter table score add foreign key(p_id) reference person(id);
check
banji int (banji between 1 and 3)

查詢(xún)表

show tables;

在表中添加字段(就是添加各種想要的屬性)(比如這里在student表中添加score)

alter table student add score double;

即 alter table 表名 add 字段 字段類(lèi)型;

添加完字段后可以   查詢(xún)表結(jié)構(gòu)

desc Student;

即 describe 表名; 或 desc 表名;

修改表名

alter table 原表名 rename to 新表名;

修改字段名(屬性名)

alter table 表名 change 原字段名  新字段名 原數(shù)據(jù)類(lèi)型;
alter table student change physics physisc char(10) not null;

//注:只有int類(lèi)型且為primary key 才可以使用auto_increment.

修改屬性(即修改修飾這個(gè)字段的數(shù)據(jù)類(lèi)型)

alter table student modify score int;

即alter table 表名 modify 字段名 數(shù)據(jù)類(lèi)型;

刪除一列

alter table 表名 drop 字段名

 

刪除一條記錄

delete  from student where score<60;
delete  from student where name=xiaohong;
delete from student where name="zhangsan" and major="yingyu";

(比如表中有兩個(gè)都是zhangsan,并且沒(méi)設(shè)置id為主鍵的話id也都是1,但是兩人專(zhuān)業(yè)不一樣,刪除的時(shí)候就要加上兩個(gè)條件,否則同名的都會(huì)被刪除)

添加一條記錄

insert into student(id,name,age,major)values(1,'張',20,80);
insert into student(id,name,age,major)values(1,"張三",20,"安卓");

(添加完可以)查看表內(nèi)內(nèi)容

select * from 表名  
select name from student where id=1;

多表查詢(xún)

select 表名.字段名 from 表1,表2... where 表1.字段=表2.字段 and 其它查詢(xún)條件;

修改某一個(gè)記錄(把表上id號(hào)為1這條記錄上的sex這個(gè)字段內(nèi)容改為女)

update people set sex='女' where id=1

排序

select * from 表名 order by 字段名 desc;
select * from 表名 order by 字段名 asc;

修改固定詞

inser into like '宋_'

網(wǎng)站名稱(chēng):SQL語(yǔ)句基本語(yǔ)法
網(wǎng)頁(yè)路徑:http://www.chinadenli.net/article2/ieosic.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供ChatGPT網(wǎng)站改版建站公司商城網(wǎng)站網(wǎng)站導(dǎo)航網(wǎng)站內(nèi)鏈

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站制作