MySQL中的创建库、表以及查询的基础语句
MySQL中的创建库、表以及查询语句对我们以后很好的应用数据库是很大有帮助的,本文中是对这些基础语 句的总结,希望会对大家有些帮助
1、创建与删除数据库 创建数据库 mysql> create database testdb; mysql> create database if not exists testdb; mysql> create schema if not exists student character set 'gbk' collate 'gbk_chinese_ci'; 删除数据库 mysql> drop database testdb;
2、创建与删除表 CREATE TABLE [if not exists] tb_name(col_name,col_definstion,constraint) 创建表 mysql> create table tb (id int unsigned not null auto_increment primary key,Name char(20) not null,Age tinyint not null); mysql> create table tb (id int unsigned not null auto_increment,Name char(20) not null,Age tinyint not null,primary key(id)); mysql> create database mydb; mysql> use mydb; mysql> create table students(name char(20) not null,age tinyint unsigned,gender char(1) not null); mysql> create table courses(ID tinyint unsigned not null auto_increment primary key,Couse varchar(50) not null); mysql> create table courses(name char(20) not null,age tinyint unsigned,gender char(1) not null); ---从一张表中查出需要的数并创建为一个新表,但是很多字段的属 性没有存在,需要自己在重新定义 mysql> create table testcourses select * from courses where CID <=2; 以其它表为模板,创建一个新表,字段的属性还会存 在 mysql> create table test like courses; 删除表:DROP TABLE tb_name; mysql> drop table testcourses; (编辑:源码网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |