Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DECIMAL(3, 2)' at line 1
CREATE TABLE student (
stud_id INT,
name_f VARCHAR(20),
email VARCHAR(20),
PRIMARY KEY(stud_id)
);
DESCRIBE student;
DROP TABLE student;
ALTER TABLE student ADD DECIMAL(3, 2);
my full code is those.
You are dropping the table before trying to add the new column. Also, you need to give the new column a name.
This makes more sense:
CREATE TABLE student (
stud_id INT,
name_f VARCHAR(20),
email VARCHAR(20),
PRIMARY KEY(stud_id)
);
ALTER TABLE student ADD newcol DECIMAL(3, 2);
DROP TABLE student; drops the table from the db so you can't manipulate it again.
Also, your alter statement does not include the column name.
You have dropped the table using the DROP TABLE student...
Therefore you can not do anything to it since it's deleted after dropping it
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
Here is the statement I have now:
INSERT INTO jobs
SELECT *
FROM proposals
JOIN commissions
ON proposals.commission_id = commissions.job_id
WHERE proposals.proposal_id = '123'
It's working fine but is creating some primary key conflicts. So, what I would like to do when the new row is entered, is this:
new primary key + commissions table data + proposals table data
Any ideas?
then if you have auto increment pk , do this :
INSERT INTO jobs ( [list of columns except the auto increment column])
SELECT ( [list of columns accordingly])
FROM proposals
JOIN commissions
ON proposals.commission_id = commissions.job_id
WHERE proposals.proposal_id = '123'
Like p.Salmon said in the comments, I would add a new column to the jobs table
ALTER TABLE Jobs add autoid INT(10)AUTO_INCREMENT PRIMARY KEY;
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
A MySQL table called SQ was created as follows,
CREATE TABLE SQ(
SQno INT PRIMARY KEY,
Question VARCHAR(100)
);
After I was trying to enter data to that table like this,
INSERT INTO SQ (SQno, Question) VALUES(
(1,'What primary school did you attend?'),
(2,'In what town or city did your parents meet?'),
(3,'In what city or town was your first job?'),
);
But there was an error occurs, and shows as this,
ERROR 1136 (21S01): Column count doesn't match value count at row 1
So, please help me to resolve this error?
You need to get rid of the outer set of parentheses; each row should have parentheses around it but not also all the rows:
INSERT INTO SQ (SQno, Question) VALUES
(1,'What primary school did you attend?'),
(2,'In what town or city did your parents meet?'),
(3,'In what city or town was your first job?')
;
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I created a table called 'parent'
Create table parent (p_id int(11) primary key, p_name varchar(255));
And another table called "child" with foreign key referenced to the parent Id table as below
Create table child (ch_id int(11), primary key, ch_name varchar(255), ch_fk int(11) references parent(p_id));
Both tables were created successfully and I add some data in both of them. But when I tried to get the data of a parent and his children it renders all available data of the child table
My query is as below.
Select * from parent , child where p_id=2
You want to join the tables explicitly - otherwise you end up with a cartesian product, where all rows on one side are joined to all rows on the other side.
I suspect what you want is:
SELECT * FROM parent p INNER JOIN child c ON p.p_id = c_ch_fk WHERE p_id=2
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I'm a newbie.. not sure if this is the right place to post this, so please forgive me if it isn't.. i wanted to find out how or what would be the best approach when it comes to making a table for contacts in a database.. Here is what i have :
I have a table for users, this table contains user info like usernames and passwords,etc.. i want to make a program that will allow these users to add contacts,now i don't want to create a contacts table for each user,i would like to have a contacts table which contains all contacts and be able to reference them using an id .. Help please
You have a table of users and a table of contacts:
User - UserID, Username, Pw... etc.
Contacts - ContactID, name, phone, info...etc.
For a user to have multiple contacts and for multiple users to have the same contact, you need to create a bridge table to handle the many to many relationship. In this table you'll reference the primary keys (the UserID, and ContactID) from the tables above.
UserContacts - UserID, ContactID. (this can be a composite primary key)
You need to have a table with name of your choice..let's say Contacts
You can have this structure
ContactId (Primary Key)
ContactName
UserId
Etc..
You can start with above structure and improvise..
I recommend this article..
http://www.datanamic.com/support/lt-dez005-introduction-db-modeling.html
Table creation sample code:
CREATE TABLE contact(
contact_id VARCHAR(20),
contact_name VARCHAR(20),
user_id VARCHAR(20),
password VARCHAR(20)
);
data insertion sample code:
INSERT INTO contact(contact_id,contact_name,user_id,password)
VALUES("A123","Daniel","dan2015","password");
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
How can I change the column position to first using ALTER query in MySQL table?
If you want your column at first position, you should use
ALTER TABLE tableName MODIFY COLUMN yourColumnName varchar(50) FIRST
For example, if your table is
Employee{FirstName,LastName,EmpId}
And if you want to move EmpId to first position
ALTER TABLE Employee MODIFY COLUMN EmpId varchar(15) FIRST;
For example :
Below query will bring empname column after department :
ALTER TABLE Employees MODIFY COLUMN empName VARCHAR(50) AFTER department;