'Write sql statement of the problem using a single statement only
I tried it with SQL Server and it was working by changing auto_increment into identity, but when it comes to MySQL, I keep getting an error:
create database Students
create table midTBSurname (
id int not null primary key AUTO_INCREMENT,
name varchar(15) not null,
Sex char(1) not null,
birthdate date not null,
address varchar(50) not null,
contactno varchar(15),
Course varchar(10) not null,
Yearlevel int not null)
insert into midTBSurname
(**name**,Sex,birthdate,address,contactno,Course,Yearlevel) VALUES
('Ruskin','M','2002-08-10','Mandaluyong City','422-5267','BSMATH','4'),
('Tristan','M','2001-07-23','Quezon','913-6791','BSN','1'),
('Therese','F','1998-06-19','Quezon','422-5267','BSIT','2'),
('Lejla','F','2001-03-07','Laguna',NULL,'BSN','1')
Select * from midTBSurname;
1 errors were found during analysis.
Unrecognized statement type. (near "name" at position 305)
Here is the version in SQL Server
create database Students
create table midTBSurname (
id int not null primary key IDENTITY,
name varchar(15) not null,
Sex char(1) not null,
birthdate date not null,
address varchar(50) not null,
contactno varchar(15),
Course varchar(10) not null,
Yearlevel int not null)
Insert into midTBSurname
(name,Sex,birthdate,address,contactno,Course,Yearlevel) values
('Ruskin','M','2002-08-10','Mandaluyong City','422-5267','BSMATH','4'),
('Tristan','M','2001-07-23','Quezon','913-6791','BSN','1'),
('Therese','F','1998-06-19','Quezon','422-5267','BSIT','2'),
('Lejla','F','2001-03-07','Laguna',NULL,'BSN','1')
Select * from midTBSurname;
This the table in SQL Server:
- id name Sex birthdate address contactno Course Yearlevel
- 1 Ruskin M 2002-08-10 Mandaluyong 422-5267 BSMATH 4
- 2 Tristan M 2001-07-23 Quezon 913-6791 BSN 1
- 3 Therese F 1998-06-19 Quezon 422-5267 BSIT 2
Solution 1:[1]
In mysql EVERY statement must be terminated with a semi-colon
drop table if exists midTBSurname;
create table midTBSurname(
id int not null primary key AUTO_INCREMENT,
name varchar(15) not null,
Sex char(1) not null,
birthdate date not null,
address varchar(50) not null,
contactno varchar(15),
Course varchar(10) not null,
Yearlevel int not null);
insert into midTBSurname
(name,Sex,birthdate,address,contactno,Course,Yearlevel) VALUES
('Ruskin','M','2002-08-10','Mandaluyong City','422-5267','BSMATH','4'),
('Tristan','M','2001-07-23','Quezon','913-6791','BSN','1'),
('Therese','F','1998-06-19','Quezon','422-5267','BSIT','2'),
('Lejla','F','2001-03-07','Laguna',NULL,'BSN','1');
Select * from midTBSurname;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | P.Salmon |
