MySQL snippets – CREATE TABLE statement sample as bash shell.
Posted by
Jiltin 15 April, 2009 1,600 views
- How to Default Timestamp and/or Update timestamps with MySQL?
- Oracle Applications Script : Sample Script to Debug the Procedure, Packages Running At Backend
- What’s a php session anyway?
- Wordpress Table Schema extracted from the database.
- Oracle Applications: Production to Development Refresh/Clone Parameter Change SQL Script.
The CREATE TABLE statement is used to create a table in MySQL.
Syntax:
CREATE TABLE table_name
(
column_name1 data_type,
column_name2 data_type,
column_name3 data_type,
….
)
(
column_name1 data_type,
column_name2 data_type,
column_name3 data_type,
….
)
sample
#!/bin/sh
#
# Developed by notesbit
# Shows all users and the user status
#
#mysql> desc user_transactions;
#+——————+————-+——+—–+——————-+——-+
#‘ Field ’ Type ‘ Null ‘ Key ‘ Default ‘ Extra ‘
#+——————+————-+——+—–+——————-+——-+
#’ appl_name ‘ varchar(20) ‘ YES ‘ ‘ NULL ‘ ‘
#‘ computer_id ’ varchar(20) ‘ YES ’ ‘ NULL ’ ‘
#’ motherboard_id ‘ varchar(20) ‘ YES ‘ ‘ NULL ‘ ‘
#‘ public_ip ’ varchar(20) ‘ YES ’ ‘ NULL ’ ‘
#’ user_name ‘ varchar(20) ‘ YES ‘ ‘ NULL ‘ ‘
#‘ transaction_date ‘ timestamp ‘ NO ‘ ‘ CURRENT_TIMESTAMP ‘ ‘
#+——————+————-+——+—–+——————-+——-+
#
mysql <<ENDOF
use testdb;
drop table user_transactions;
create table user_transactions
(
appl_name varchar(20),
computer_id varchar(20),
motherboard_id varchar(20),
public_ip varchar(20),
user_name varchar(20),
transaction_date TIMESTAMP DEFAULT NOW()
);
ENDOF
#
# Developed by notesbit
# Shows all users and the user status
#
#mysql> desc user_transactions;
#+——————+————-+——+—–+——————-+——-+
#‘ Field ’ Type ‘ Null ‘ Key ‘ Default ‘ Extra ‘
#+——————+————-+——+—–+——————-+——-+
#’ appl_name ‘ varchar(20) ‘ YES ‘ ‘ NULL ‘ ‘
#‘ computer_id ’ varchar(20) ‘ YES ’ ‘ NULL ’ ‘
#’ motherboard_id ‘ varchar(20) ‘ YES ‘ ‘ NULL ‘ ‘
#‘ public_ip ’ varchar(20) ‘ YES ’ ‘ NULL ’ ‘
#’ user_name ‘ varchar(20) ‘ YES ‘ ‘ NULL ‘ ‘
#‘ transaction_date ‘ timestamp ‘ NO ‘ ‘ CURRENT_TIMESTAMP ‘ ‘
#+——————+————-+——+—–+——————-+——-+
#
mysql <<ENDOF
use testdb;
drop table user_transactions;
create table user_transactions
(
appl_name varchar(20),
computer_id varchar(20),
motherboard_id varchar(20),
public_ip varchar(20),
user_name varchar(20),
transaction_date TIMESTAMP DEFAULT NOW()
);
ENDOF

Comments
No comments yet.