MySQLは必ずできます。もし読み終わったらまだできないなら、道を狭くするかもしれません。
MySQL
1、サーバの下のすべてのデータベースを表示します。
書式:(1)表のすべての変更フィールドの値を変更します。
キーワード:select
フォーマット:(1)すべてのクエリー:
クエリーstudentテーブルのすべてのレコード:
(1)フィールドの別名:フィールドasの別名(2)表の別名:表名asの別名
注意:asは省略できます。
b、再検索:キーワード:distinct
c、演算クエリ:クエリの構造selectの後で基本的な要素をサポートします。
商品の検索には商品ID、商品名、商品分類が表示されます。
a、比較演算子:
キーワード:order by
ソート方法:
各カテゴリーの商品の個数を集計します。
1.作成手順
(1)fromテーブル名(2)where条件(3)group byフィールド名(4)having条件(5)select*(6)order by
13、sql拘束のメインキー制約
機能:標識表にデータが唯一存在するキーワード:primrykey特徴:一意、非空
メインキーを追加します。a、テーブルを作成する場合、フィールドの説明
DDLの表構造修正
メインキー制約を削除:
作用:変更されたフィールド値の一意性を強制的に識別する
一意制約と主結合制約の違い:
一意の索引を削除:
列にデフォルトを設定する
キーワード:default
デフォルトの制約を追加
例:
修飾された列にデータを追加すると、自動的にキーワードが追加されます。increment
追加時の注意事項:
a.作成時
キーワード:foreign key
役割:多表間の関係を維持する
特徴:表の外ボタンからメインテーブルのキーを参照します。
作成時に追加
19、複数テーブルクエリのデータは複数のテーブル基本文法から来ています。
需要:各部門の下にどのような人がいますか?
1、サーバの下のすべてのデータベースを表示します。
show databases;
2、現在そのデータベースを操作していることを確認します。select database();
3、day 01データベースに切り替えます。use day01;
4、day 01データベースの定義情報を確認する:show create database day01;
1、テーブルを作成する:create table (
( ) ,
( )
)
2、現在のデータベースの下にあるすべてのテーブルを表示します。show tables;
データテーブルの構造を表示します。desc ;
建表文を表示する:show create table :
表示エンジン:show engines;
3、テーブルの削除drop table
4、表の書式を変更する: alter table ......
(1)テーブル追加フィールドの末尾追加を変更します。 alter table add ( ) .
ヘッダの追加: alter table add ( ) first;
指定されたフィールドの後にテーブルフィールドを追加します。 alter table add ( ) after ;
(2)テーブルデータの種類、長さ、制約を変更する alert table modify ( ) .
(3)テーブルフィールドの名前を変更する alter table change
(4)テーブルフィールドの削除 alter table drop
(5).表の名称を変更するrename table to
(6).表の文字セットを変更するalter table character set
5、DMLの追加操作DML:データ操作言語の追加削除修正キーワード:insert intoフォーマット: insert into ( 1, 2...)values( 1, 2...)
a、単一の値(name)を挿入する:insert into student (cname) values (" ");
b、単一の値(cid)を挿入する:insert into student (cid) values(1);
c、複数の値を挿入する:insert into student values (4," "),(5," “),(6," “):
6、DMLの修正操作キーワード:udate書式:(1)表のすべての変更フィールドの値を変更します。
update set = ;
(2)条件に応じて修正する update set = where ;
需要:studentテーブルに記録されているすべてのcnameフィールド値を携帯電話に変更します。update student set cname=" ";
需要:student表のcidを1とする分類名をコンピュータに変更します。update student set cname=' ' where cid=1;
7、DMLの削除操作キーワード:deleteフォーマット:(1)すべてのデータを削除する:delete from ;
(2)条件に応じてデータを削除する: delte from where ;
delete fromとtruncateの違い。 1.delete from
2.truncate ,
需要:cidが0のデータを削除します。delect from student where cid=0;
delect from student wherer cname=' ‘;
需要:studentテーブルのすべてのデータを削除します。(1) delect from student;
(2) truncate student;
8、DQLの照会キーワード:select
フォーマット:(1)すべてのクエリー:
select *from ;
(2)条件照会:select *from wher ;
*:表のすべてのフィールドを表します。クエリーstudentテーブルのすべてのレコード:
select *from student;
クエリーstudentテーブル内のすべてのレコードは、pidとpnameフィールドのみを表示します。select pid,pname from student;
a、エイリアスクエリ(1)フィールドの別名:フィールドasの別名(2)表の別名:表名asの別名
注意:asは省略できます。
b、再検索:キーワード:distinct
c、演算クエリ:クエリの構造selectの後で基本的な要素をサポートします。
商品の検索には商品ID、商品名、商品分類が表示されます。
SELECT DISTINCT(category_name) FROM product;
商品表を調べて、すべての商品の価格+10元を表示します。SELECT price AS " ",price+10 AS " " FROM product;
9、DQLの条件照会 : where
: where
:
select *from where ;
ポイント:条件の組み合わせa、比較演算子:
> < >= <= != <> =
範囲: between and [100 ,200)
in( 1, 2) or 1 or 2
like
%:
_:
: java java%
: java %java
: java %java%
is null:
is not null:
b、論理演算子 and or not
商品名は「プレイボーイ」の商品情報はすべて以下の通りです。select *from product where pname=" ";
検索価格は800商品です。select *from product where price=800;
検索価格は800ではないすべての商品です。select *from product where price!=800;
select *from product where price <>800;
商品の価格が60元以上の商品情報を調べます。select *from product where price >60;
商品の価格を調べます。200から1000までのすべての商品です。select *from product where price >=200 and price <=1000;
select *from product where price between 200 and 1000;
商品の価格を調べます。200か800か2000の商品は全部です。select *from product where price=200 or price=800 or price=2000;
select *from product where price in(200,800,2000);
「覇」の文字が含まれているすべての商品を調べます。select *from product where pname like "% %";
二番目の文字は「想」の商品を全部調べます。select *from product where pname "_ %";
商品の分類がない商品select *from product where category_name is null;
分類のある商品を調べたらnullではないです。select *from product where category_name is not null;
10、単表の並べ替えクエリキーワード:order by
ソート方法:
1. : asc ( )
2. : desc
書式:select *from order by
a、使用価格並べ替え(降順):select *from product order by price desc;
b、価格並べ替え(降順)に基づいて、主キーで並べ替え(降順)、つまり価格が同じなら、同じ価格のデータをpid降順で並べ替える。select *from product order by price desc,pid desc;
d、商品の価格を表示し(繰り返しに行く)、並べ替え(降順)select distinct(price) from product order by price desc;
10、単表の重合関数 :
a、 :count
b、 : max
c、 :min
e、 :avg
f、 :sum
: null
商品の総件数、総価格、最大価格、最小価格、価格の平均値を調べる。select count(*),sum(price),max(price),min(price),avg(price) from product;
照会価格は200商品の総件数より大きいです。select count(*) from product where price>200;
検索分類は「パソコン事務」の全商品の総記録です。select count(*) from product where category_name=" ";
検索は「服装」に分類されています。すべての商品の平均価格です。select avg(price) from product where category_name =" ";
11、単表のグループ操作キーワード:group byフォーマット:select *from where group by having
where条件:グループ化前にデータをフィルタリングするためにwhere having条件を使用します。グループ化後にフィルタリング条件havingをフィルタリングします。各カテゴリーの商品の個数を集計します。
select category_name,count(*) from product group by category_name;
select category_name,count(*) from product where categore_name is not null group by category_name;
select category_name,count(*) from product group by category_name having category_name is not null;
12、sqlの順番1.作成手順
select *from where group by having order by
2.実行順序(1)fromテーブル名(2)where条件(3)group byフィールド名(4)having条件(5)select*(6)order by
13、sql拘束のメインキー制約
機能:標識表にデータが唯一存在するキーワード:primrykey特徴:一意、非空
メインキーを追加します。a、テーブルを作成する場合、フィールドの説明
create table (
( )primary key
)
b、表作成時に、contrint制約エリアでcreate table (
( ),
( ),
primary key( )
)
c、表を作成し、メインキーを追加するDDLの表構造修正
alter table add [constraint ] primary key( )
注意:テーブルを作成して追加し、追加する前にデータの完全性を確認する必要があります。メインキー制約を削除:
alter table drop primary key
注意:メインキーを削除しても、空の制約があります。例:a.テーブルを作成する場合、フィールド記述部create table p0(
id int primary key,
name varchar(32),
idCardrd varchar(16)
)
b.表を作成する時、constrant制約エリアcreate table p1(
id int ,
name varchar(32),
idCardrd varchar(16)
primary key(id)
)
c.テーブルを作成し、メインキーを追加するcreate table p2(
id int ,
name varchar(32),
idCardrd varchar(16)
)
alter table add constraint pk_p2 primary key(id);
d.メインキーの削除alter table p2 drop primary key;
14、非空制約作用:強制的に修飾された列はnull値のキーワードを受信しない:not null a.テーブルを作成する時、フィールド宣言所b.テーブルを作成し、非空制約を追加します。alter table modify ( )
c.制約の削除alter table modify ( )
例:a.テーブルを作成する場合、フィールド宣言部create table p4(
id int prinary key,
name varchar(32) not null,
idCard varchar(16)
)
b.表を作成すると、空の制約を追加します。create table p5(
id int prinary key,
name varchar(32),
idCard varchar(16)
)
alter table p5 modify name varchar(32) not null;
c.制約の削除alter table p5 modify name varchar(32);
15、一意制約作用:変更されたフィールド値の一意性を強制的に識別する
一意制約と主結合制約の違い:
a.
b. ,
c. null, null
キーワード:uniquea. ,
b. , constraint
c.
alter table add [constraint ] unique( )
外部キー制約を追加する場合、制約名が指定されていない場合は、デフォルトはフィールド名です。一意の索引を削除:
alter table dorp index
例:a.フィールド説明部create table p6(
id int primary key,
name varchar(32) unique,
inCard varchar(16)
)
b.com nstrint制約エリアcreate table p7(
id int primary key,
name varchar(32),
unique(name)
)
c.テーブル作成後create table p8(
id int primary key,
name varchar(32),
)
alter table p8 add constraint p8_u unique(name);
d.索引の削除alter table p8 drop index p8_u;
16、デフォルトの制約列にデフォルトを設定する
キーワード:default
デフォルトの制約を追加
create table (
id ( ),
name ( )default " "
)
特徴:デフォルトのフィールドの割り当てを指定しないと、自動的にデフォルトの値を選択します。例:
create table p9(
id int primary key,
name varchar(200) default " ",
inCard varchar(50),
unique(name)
)
17、自動成長戦略:修飾された列にデータを追加すると、自動的にキーワードが追加されます。increment
追加時の注意事項:
a.
b. ( )
自動成長パターンを追加:a.作成時
create table (
id ( )primary key auto_increment
)
alter table modify ( ) auto_increment;
18、外部キー制約キーワード:foreign key
役割:多表間の関係を維持する
特徴:表の外ボタンからメインテーブルのキーを参照します。
:
:
外部キーの設定は表からで、外部キーの値はメインテーブルのキーから取らなければなりません。作成時に追加
foreign key( ) references ( )
特徴:a.外キーは表からb.外キーデータを追加して表の主キーc.外キーから引用した表データはdを削除できません。外キーの種類と長さはメインキーと一致していなければなりません。メインキーフィールドは空で唯一、外キーフィールドは重複できます。空です。19、複数テーブルクエリのデータは複数のテーブル基本文法から来ています。
select *from 1, 2......
複数テーブルクエリの方式:内連結、外連結、左外部接続、右外部接続、サブクエリ、自己クエリ需要:各部門の下にどのような人がいますか?
selsect emp.*,dept.name from emp,dept where emp.dept_id=dept. id;