- output after repeated back to weight values of all the two conditional statement where statement with
the SELECT Sname the FROM Student
the UNION
the SELECT Sname the FROM student1
- repeating all the output values included in
the SELECT Sname the FROM Student
the UNION ALL
the SELECT Sname the FROM student1
-The SQL statement MySql does not support SELECT INTO to select data from one table and then insert the data into another table. It is often used to create a backup copy of the table and archive the records.
SELECT *
INTO school_timetable [in stu]-You can not Follow
FROM school_timetable_copy
-Use this instead of Create table Table2 (Select * from Table1); Create table school_t
(Select * from school_timetable);
- define the field attribute data type DECIMAL (size, d) size is a predetermined maximum number of bits array of digits to the right of the decimal point d
- receiving a variable length string VARCHAR (accommodates letters, numbers, special characters)
- -DATE (yyyymmdd) accommodates the date
-Constraints
-not NULL constraints force columns not to accept null
-UNIQUE constraints uniquely identify each record and primary KEY in a database table are columns, column sets provide unique guarantee values that do not allow duplicates, unique
-PRIMARY key With uniquely defined unique
-two ways to add constraints to columns 1-> CREATE when creating a table ..... 2-> Add ALTER TABLE after the table is created. . .
-Add the primary key PRIMARY key Same as above
CREATE TABLE stu (
id int not null,
UNIQUE (id))
ALTER TABLE student
ADD UNIQUE (Sname)
-Mysql undo unique constraint
ALTER TABLE student
DROP INDEX Sname
-SQL undo unique undo PRIMARY key
ALTER TABLE student
DROP CONSTRAINT Sname
-- Mysql 撤销PRIMARY key
ALTER TABLE school_t
DROP PRIMARY KEY
-Two ways to create foreign keys 1-> Sname VARCHAR FOREIGN KEY references school_timetable (Sname) when creating a table followed by the primary key of another table--
2-> The table has been created and
ALTER TABLE student
add FOREIGN KEY has been created with alter (Sname)
REFERENCES school_timetable (Sname)
-Undo foreign key constraint
ALTER TABLE student
DROP FOREIGN key Sname
-DEFAULT constraint is used to insert default values into columns-
Two ways to create default values 1-> city VARCHAR (255) DEFAULT 'China' when creating a table
-2-> Alter table stu has been created for MySql table ALTER TABLE stu
-ALTER city SET DEFAULT 'China' ALTER city DROP DEFAULT
-For Sql oracle ALTER TABLE stu ALTER TABLE stu
-ALTER COLUMN city SET DEFAULT 'China' ALTER COLUMN city COLUMN DEFAULT 'China'
-Create index Allow duplicate values CREATE INDEX INDEX_name
ON student (Sname)
-Create index unique index CREATE UNIQUE INDEX INDEX_name
ON student (Sname)
-- 撤销 索引 MySsql : ALTER TABLE TABLE_name DROP INDEX INDEX_name
-- IBM,Orcale: DROP INDEX_name
-Delete or add columns in the table
ALTER TABLE student
add ss varchar (255)
ALTER TABLE student
DROP COLUMN ss
-SQL changes the data type of the columns in the table
ALTER TABLE student
ALTER COLUMN Grade VARCHAR (255)
-MySQL changes the data type of the columns in the
table alter table student modify column Grade varchar (20);
-Change column name and column name type alter table student change column sname stuname varchar (20);