日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

mysql常规使用(建立,增删改查,视图索引)

發布時間:2025/3/8 数据库 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql常规使用(建立,增删改查,视图索引) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

目錄

1.數據庫建立
2.增刪改查
3.視圖建立:

1.數據庫建立

mysql> mysql> show databases; +-----------------------------------+ | Database | +-----------------------------------+ | information_schema | | challenges | | dvwa | | hdcms | | my | | mysql | | performance_schema | | security | | #mysql50#sql | | test | | us | | usualtoolcms-utf8-8.0-build181008 | +-----------------------------------+ 12 rows in set, 1 warning (0.00 sec)mysql> use mysql Database changed mysql> use mysql; Database changed mysql> show tables-> ; +---------------------------+ | Tables_in_mysql | +---------------------------+ | columns_priv | | db | | event | | func | | general_log | | help_category | | help_keyword | | help_relation | | help_topic | | host | | ndb_binlog_index | | plugin | | proc | | procs_priv | | proxies_priv | | servers | | slow_log | | tables_priv | | time_zone | | time_zone_leap_second | | time_zone_name | | time_zone_transition | | time_zone_transition_type | | user | +---------------------------+ 24 rows in set (0.11 sec)mysql> Create Database Bigpigfoot; Query OK, 1 row affected (0.00 sec)mysql> show databases-> ; +-----------------------------------+ | Database | +-----------------------------------+ | information_schema | | bigpigfoot | | challenges | | dvwa | | hdcms | | my | | mysql | | performance_schema | | security | | #mysql50#sql | | test | | us | | usualtoolcms-utf8-8.0-build181008 | +-----------------------------------+ 13 rows in set, 1 warning (0.00 sec)mysql> use bigpigfoot; Database changed mysql> show tables-> ; Empty set (0.00 sec)mysql> create table Student(Sno CHAR(5) not NULL unique); Query OK, 0 rows affected (0.47 sec)mysql> show tables; +----------------------+ | Tables_in_bigpigfoot | +----------------------+ | student | +----------------------+ 1 row in set (0.00 sec)mysql> drop table student; Query OK, 0 rows affected (0.00 sec)mysql> create table student(Sname VarCHAR(20) unique,Ssex CHAR(1), Sage INT,Sdept CHAR(15))-> ; Query OK, 0 rows affected (0.12 sec)mysql> show tables; +----------------------+ | Tables_in_bigpigfoot | +----------------------+ | student | +----------------------+ 1 row in set (0.00 sec)mysql> create table Course(Cno CHAR(4) PRIMARY KEY,Cname VarCHAR(40),Cpno CHAR(4),Ccredit SMALLINT,FOREIGN KEY (Cpno) REFERENCES Course(Cno)); Query OK, 0 rows affected (0.34 sec)mysql> show tables; +----------------------+ | Tables_in_bigpigfoot | +----------------------+ | course | | student | +----------------------+ 2 rows in set (0.00 sec)mysql> CREATE TABLE SC(-> Sno CHAR(5),-> Cno CHAR(3),-> Grade int,-> Primary key (Sno, Cno)); Query OK, 0 rows affected (0.12 sec)mysql> mysql> ALTER TABLE Student ADD Scome DATETIME-> ; Query OK, 0 rows affected (0.39 sec) Records: 0 Duplicates: 0 Warnings: 0mysql> show tables; +----------------------+ | Tables_in_bigpigfoot | +----------------------+ | course | | sc | | student | +----------------------+ 3 rows in set (0.00 sec)mysql> select * from student-> ; Empty set (0.00 sec)mysql> CREATE TABLE Student mysql> desc student; +-------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+-------------+------+-----+---------+-------+ | Sname | varchar(20) | YES | UNI | NULL | | | Ssex | char(1) | YES | | NULL | | | Sage | int(11) | YES | | NULL | | | Sdept | char(15) | YES | | NULL | | | Scome | datetime | YES | | NULL | | +-------+-------------+------+-----+---------+-------+ 5 rows in set (0.11 sec)ALTER TABLE Student ALTER COLUMN Sage SMALLINT;ALTER TABLE Student ALTER ' at line 1 mysql> CREATE UNIQUE INDEX SCno ON SC(Sno ASC,Cno DESC); ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ASC??Cno DESC)' at line 1 mysql> CREATE UNIQUE INDEX Stusno ON Student(Sno); ERROR 1072 (42000): Key column 'Sno' doesn't exist in table mysql> ALTER TABLE Student ADD Sno datetime; Query OK, 0 rows affected (0.15 sec) Records: 0 Duplicates: 0 Warnings: 0mysql> CREATE UNIQUE INDEX Stusno ON Student(Sno); Query OK, 0 rows affected (0.12 sec) Records: 0 Duplicates: 0 Warnings: 0mysql> CREATE UNIQUE INDEX Coucno ON Course(Cno); Query OK, 0 rows affected (0.11 sec) Records: 0 Duplicates: 0 Warnings: 0mysql> desc student; +-------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+-------------+------+-----+---------+-------+ | Sname | varchar(20) | YES | UNI | NULL | | | Ssex | char(1) | YES | | NULL | | | Sage | int(11) | YES | | NULL | | | Sdept | char(15) | YES | | NULL | | | Scome | datetime | YES | | NULL | | | Sno | datetime | YES | UNI | NULL | | +-------+-------------+------+-----+---------+-------+ 6 rows in set (0.01 sec)mysql> DROP TABLE SC; Query OK, 0 rows affected (0.00 sec)mysql> show tables; +----------------------+ | Tables_in_bigpigfoot | +----------------------+ | course | | student | +----------------------+ 2 rows in set (0.00 sec)mysql> show databases; +-----------------------------------+ | Database | +-----------------------------------+ | information_schema | | bigpigfoot | | challenges | | dvwa | | hdcms | | my | | mysql | | performance_schema | | s_t2 | | security | | #mysql50#sql | | test | | us | | usualtoolcms-utf8-8.0-build181008 | +-----------------------------------+ 14 rows in set, 1 warning (0.46 sec)mysql> create database S_T3; Query OK, 1 row affected (0.00 sec)mysql> DROP database S_T3; Query OK, 0 rows affected (0.27 sec)mysql> create database S_T3; Query OK, 1 row affected (0.00 sec)mysql> use S_T3; Database changed mysql> create table Student(Sno char(5) unique not NULL,Sname char(20) unique,Sage int,Sinst char(20)); Query OK, 0 rows affected (0.38 sec)mysql> create table Institute(Sinst char(20) unique,Ilocation char(20),Icall char(20)); Query OK, 0 rows affected (0.10 sec)mysql> insert into Student values('1913','daming',20,'ruanjian'); Query OK, 1 row affected (0.00 sec)mysql> insert into Student values('1914','lili',22,'dashuju'); Query OK, 1 row affected (0.00 sec)mysql> insert into Student values('1915','王國煜',23,'軟件學院'); Query OK, 1 row affected, 4 warnings (0.08 sec)mysql> insert into institute values('ruanjian','田園','123456'); Query OK, 1 row affected, 2 warnings (0.00 sec)mysql> insert into institute values('軟件','田園','123456'); Query OK, 1 row affected, 4 warnings (0.00 sec)mysql> insert into institute values('dashuju','東區','456789'); Query OK, 1 row affected, 2 warnings (0.00 sec)mysql> show databases-> ; +-----------------------------------+ | Database | +-----------------------------------+ | information_schema | | bigpigfoot | | challenges | | dvwa | | hdcms | | my | | mysql | | performance_schema | | s_t2 | | s_t3 | | security | | #mysql50#sql | | test | | us | | usualtoolcms-utf8-8.0-build181008 | +-----------------------------------+ 15 rows in set, 1 warning (0.00 sec)mysql> show tables; +----------------+ | Tables_in_s_t3 | +----------------+ | institute | | student | +----------------+ 2 rows in set (0.00 sec)mysql> desc institute; +-----------+----------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------+----------+------+-----+---------+-------+ | Sinst | char(20) | YES | UNI | NULL | | | Ilocation | char(20) | YES | | NULL | | | Icall | char(20) | YES | | NULL | | +-----------+----------+------+-----+---------+-------+ 3 rows in set (0.34 sec)mysql> desc student; +-------+----------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+----------+------+-----+---------+-------+ | Sno | char(5) | NO | PRI | NULL | | | Sname | char(20) | YES | UNI | NULL | | | Sage | int(11) | YES | | NULL | | | Sinst | char(20) | YES | | NULL | | +-------+----------+------+-----+---------+-------+ 4 rows in set (0.01 sec)mysql>

2.增刪改查








3.視圖建立:



整理了一下過去所學的東西…

總結

以上是生活随笔為你收集整理的mysql常规使用(建立,增删改查,视图索引)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。