New Ket Network online programming Website: Https://www.nowcoder.com/activity/oj
(SQLite is used by default)
Topic 1:
Get the execution plan for select * FROM Employees
Select * from Employees;
Topic 2:
Last_Name and first_name of all employees of the Employees table are stitched together as name, separated by a space
CREATE TABLE' Employees ' (' emp_no ')int( One) not NULL, ' birth_date ' date not NULL, ' first_name 'varchar( -) not NULL, ' last_name 'varchar( -) not NULL, ' Gender 'Char(1) not NULL, ' hire_date ' date not NULL,PRIMARY KEY(' Emp_no '));
SELECT last_name| | ' ' || from Employees;
"||" To connect strings, MySQL, SQL Server, Oracle and so on are also supported with "+" to connect.
In MySQL, you can do this with the Concat function:
SELECT ' ' from Employees;
You can also use stuff to connect the data in the same column: http://blog.csdn.net/rolamao/article/details/7745972
Topic 3:
Create an actor table that contains information such as the following
List |
type | is
null |
meaning |
actor_id |
smallint (5) |
NOT NULL |
Primary Key ID |
First_Name |
varchar (45) |
NOT NULL |
Name |
Last_Name |
varchar (45) |
NOT NULL |
Surname |
Last_update |
Timestamp |
NOT NULL |
Last update time, default is the current time of the system |
CREATE TABLEactor (actor_idsmallint(5)PRIMARY KEY not NULL, first_namevarchar( $) not NULL, Last_Namevarchar( $) not NULL, Last_updatetimestamp not NULL DEFAULT(datetime(' Now','localtime')));
Note that the parentheses outside the datetime (' Now ', ' localtime ') must not be omitted.
The CREATE statement is best supplemented by the Create TABLE IF not EXISTS actor (...);
Topic 4:
For the table actor, BULK insert the following data:
actor_id |
first_name |
last_name |
last_update |
1 |
PENELOPE |
Guiness |
2006-02-15 12:34:33 |
2 |
NICK |
Wahlberg |
2006-02-15 12:34:33 |
INSERT intoactor (actor_id, first_name, last_name, last_update)VALUES(1,'PENELOPE','Guiness','2006-02-15 12:34:33'),(2,'NICK','Wahlberg','2006-02-15 12:34:33');
Topic 5:
INSERT OR into actor (actor_id, first_name, last_name, last_update) VALUES ('3'ED'CHASE') '2006-02-15 12:34:33');
You can also replace "IGNORE" with "replace".
In MySQL, insert IGNORE into actor (remove "or").
SQL Exercises (3)-New Ket Network