经典SQL语句

时间:2024-06-17 18:44:44 SQL

经典SQL语句大全

  1、创建数据库: create database 数据库名

  如:create database student;

  2、连接到一个已经存在的数据库: use 数据库名

  如:use student;

  3、删除数据库:drop database 数据库名

  如: drop database student;

  4、创建表:create table 表名列名列的数据类型列的约束])

  如:create table stuInfo(stuId int primary key,stuName var20) not null)

  5、删除表: 表名

  如: stuInfo;

  6、修改表:alter table

  给表添加新列: alter table 表名 add 列名列的数据类型

  添加多列,中间用逗号隔开

  如:alter table stuInfo add stuGender var10)

  修改某列的数据类型:alter table 表名 modify 列名新数据类型

  如:alter table stuInfo modify stuGender int

  修改列名:alter table 表名 change 老列名新列名数据类型

  如:alter table stuInfo change stuName stuAddress var30)

  删除列:alter table 表名 drop 列名

  如: alter table stuInfo drop stuGender

  7、将创建的表的语句反向导出: show create table 表名

  8、查询表的所有内容:select * from 表名

  查询表的部分内容: select 列名列表 from 表名

  9、查询表结构:show columns from 表名

  10、插入单行数据: into 表名列名列表) values(值列表)

  11、插入多行数据:作用相当于将数据从一个表复制到另一个表

   into 表名 (列名列表) select

  如将stuInfo表中的所有的学生姓名复制到students表中的stuName列中: into students(stuName) select stuName from stuInfo

  12、删除数据: from 表名 where过滤条件

  如删除stuID为4的人的数据: from stuInfo where stuId=4

【经典SQL语句】相关文章:

oracle的sql语句01-21

SQL查询语句大全10-24

SQL语句的理解原则10-05

mysql SQL语句积累参考10-02

sql语句的各种模糊查询08-25

Oracle的sql语句模拟试题及答案10-12

SQL语句中的正则表达示07-28

SQL优化大全09-09

2016最新J2EE中SQL语句自动构造方法08-02

PHP防止SQL注入的例子09-25