SQL Exercises (3)-New Ket Network

Source: Internet
Author: User
Tags bulk insert

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 typenull 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.