本文目錄一覽:
mysql中,如何創建一個表,並加一條數據?
1、使用 create table 語句可完成對錶的創建, create table 的創建形式:
create table 表名稱(列聲明);
以創建 people 表為例, 表中將存放 學號(id)、姓名(name)、性別(sex)、年齡(age) 這些內容:
create table people(
id int unsigned not null auto_increment primary key,
name char(8) not null,
sex char(4) not null,
age tinyint unsigned not null
);
其中,auto_increment就可以使Int類型的id欄位每次自增1。
2、向表中插入數據使用insert 語句。
insert 語句可以用來將一行或多行數據插到資料庫表中, 使用的一般形式如下:
insert [into] 表名 [(列名1, 列名2, 列名3, …)] values (值1, 值2, 值3, …);
其中 [] 內的內容是可選的, 例如, 要給上步中創建的people 表插入一條記錄, 執行語句:
insert into people(name,sex,age) values( “張三”, “男”, 21 );
3、想要查詢是否插入成功,可以通過select 查詢語句。形式如下:
select * from people;
擴展資料:
當mysql大批量插入數據的時候使用insert into就會變的非常慢, mysql提高insert into 插入速度的方法有三種:
1、第一種插入提速方法:
如果資料庫中的數據已經很多(幾百萬條), 那麼可以 加大mysql配置中的 bulk_insert_buffer_size,這個參數默認為8M
舉例:bulk_insert_buffer_size=100M;
2、第二種mysql插入提速方法:
改寫所有 insert into 語句為 insert delayed into
這個insert delayed不同之處在於:立即返回結果,後台進行處理插入。
3、第三個方法: 一次插入多條數據:
insert中插入多條數據,舉例:
insert into table values(’11’,’11’),(’22’,’22’),(’33’,’33’)…;
mysql資料庫怎麼創建數據表並添加數據
1、創建一個資料庫test2
代碼:mysql create database test2;
截圖:
2、創建一個mytable表
代碼: mysql create table mytable (name varchar(20), sex char(1),
– birth date, birthaddr varchar(20));
截圖:
3、顯示錶結構
代碼:mysql describe mytable;
截圖:
4、向表中插入一條記錄
代碼:mysql insert into mytable
– values(
– ‘abc’,’f’,’1988-07-07′,’chian’);
截圖:
mysql怎麼用語句建表
mysql使用create語句進行創建資料庫表,具體語法:
CREATE TABLE table_name (column_name column_type);
其中需要表名,表中欄位名,欄位屬性;示例:創建一個學生信息表 sql如下
CREATE TABLE IF NOT EXISTS `student`(
`student_id` INT UNSIGNED AUTO_INCREMENT,
`student_name` VARCHAR(100) NOT NULL,
`student_age` int(3) NOT NULL,
PRIMARY KEY ( `student_id` ))ENGINE=InnoDB DEFAULT CHARSET=utf8;
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/293623.html