|
CREATE TABLE relation_name ( attr_name1 type1 [attr_constraint1] , attr_name2 type2 [attr_constraint2] , .... attr_namen typen [attr_constraintn] [ , integrity constrains ] ); |
Defines the relation named relation_name with attributes:
|
|
|
fixed point numbers are accurate and do NOT have round off errors Example:
NOTE:
|
|
|
|
SQL includes the number of characters of the string when it stores a VARCHAR value In total, VARCHAR(n) stores n + 2 bytes, the 2 extra bytes is for the string length |
NOTE: To denote string, use single quotes: 'John'
|
|
NOTE: To denote bit string 10101, use: B'10101'
|
NOTE:
When comparing two values x and y, if either
x
or
y
is
NULL ,
then some logical comparisons
evaluate to an UNKNOWN
value rather than true or false, e.g.:
|
|
NOTE:
|
NOTE:
|
NOTE:
|
/home/cs377001/companyDB |
create database companyDB; use companyDB; create table department (dname char(15) not null, dnumber int not null, mgrssn char(9) not null, mgrstartdate char(10) ); create table employee (fname char(6) not null, minit char(1), lname char(8) not null, ssn char(9) not null, bdate char(10), address char(25), sex char(1), salary decimal(7,2), superssn char(9), dno int default 1 not null); create table dept_loc (dnumber int not null, dlocation char(10) not null ); create table project (pname char(15) not null, pnumber int not null, plocation char(10), dnum int not null); create table works_on (essn char(9) not null, pno int not null, hours decimal(5,1) not null); create table dependent (essn char(9) not null, name char(10) not null, sex char(1), bdate char(10), relationship char(10)); |
cheung-sql use companyDB; show tables; |
CREATE TABLE test ( name char(10), addr varchar(10), id int, salary dec(9,2), bdate date ); |
INSERT INTO test values ( 'John', '123 H Lane', 12345, 45000.65, DATE'1970-4-1' ); |
SELECT * from test; |
DROP TABLE test; |
show databases list all databases in mySQL use DBName Set current DB to DBName show tables List the tables in the current DB SELECT DATABASE() Return the name of the current DB describe TableName Display the structure of table TableName |
|