テーブル作成

create table tab1(col1 int);

create table tab2(col1 int,col2 varchar2(10), col3 date);
alter table tab2 add constraint tab2p primary key (col1);

 

--テーブル確認
show tables;
show tables from test;
show tables in test;
show full tables;
show full tables like '%tab%';


--テーブル作成
create table tab1(col1 int);
create table tab3(col1 int primary key,col2 date);
create table tab4(col1 int primary key auto_increment,col2 int);

create table tab5(col1 decimal,col2 decimal ,primary key(col1,col2));

create table tab6
( col1 int not null auto_increment,
col2 char(30),
col3 date,
col4 int,
primary key (col1,col2),
unique ind61 (col3),
index ind62 (col4)
);


create table tab7
(col1 int,col2 int,col3 int);

--テーブル定義確認
show create table tab1;

desc tab1;
show columns from tab1;

--同じ定義のテーブル作成
create table tab2 like tab1;


create table oya(id int not null, name varchar(10),primary key(id));
create table ko(id int not null,name varchar(10), id2 int,primary key (id)
,foreign key(id2) references oya(id)
);


--権限付与

grant all on *.* to 'user3'@'%';
grant all on test.* to 'user3'@'%';
grant select,update on test.tab2 to 'user3'@'%';
grant select,update on table test.tab2 to 'user3'@'%';
grant select(col1) on test.tab2 to 'user3'@'%';
grant update(col2) on test.tab2 to 'user3'@'%';
grant insert(col2) , update(col2) on test.tab2 to 'user3'@'%';
grant all on *.* to 'user3'@'%' with grant option;
grant alter routine on PROCEDURE test.proc1 to 'user3'@'%';


--MyISAMテーブル
create table tab201(col1 char(50)) row_format = fixed engine=myisam;
create table tab202(col1 char(50)) row_format = dynamic engine=myisam;

 


\d+
\dt+

\d+ tab1
\d+ tab2

create table tab1(col1 int,col2 varchar(10)) tablespace tbs1;

create table tab2
(
col1 int not null,
col2 int not null,
col3 varchar(100),
col4 date,
col5 date,
primary key(col1,col2),
unique(col3)
) tablespace tbs1;

create table tab3(col1 int);
create table tab4(col1 int);


CREATE TABLE cities (
city varchar(80) primary key,
location point
);

CREATE TABLE weather (
city varchar(80) references cities(city),
temp_lo int,
temp_hi int,
prcp real,
date date
);

CREATE TABLE dbo.tab1 (col1 int , col2 int );
go

CREATE TABLE dbo.tab2 (col1 int not null);
go

CREATE TABLE dbo.tab3 (col1 int not null);
go

CREATE TABLE tab4 (col1 int ,col2 datetime ,col3 varchar(100));
go

CREATE TABLE tab5 (col1 int ,col2 datetime ,col3 varchar(100));
go

 

CREATE TABLE schema1.tab101 (col1 int , col2 int );
go

--主キー追加(クラスター化インデックス)
use test
go
alter table dbo.tab2 add constraint tab2p primary key CLUSTERED (col1);
go

--主キー追加(非クラスター化インデックス)
use test
go
alter table dbo.tab3 add constraint tab3p primary key NONCLUSTERED (col1);
go

--カラム追加
alter table tab2 add col2 integer ;
go