I'm trying to create my first database and it's my first time using SQL Server. The software is a little confusing to me, right now I have a database but when I execute it I get a lot of errors. I tried following a guide but it didn't show any errors when he ran it.
I'm trying to create a database that is a stream website. This is what I have so far: These are my errors: I don't understand any of them, how is my syntax wrong? I've only used Java before so this is all a little overwhelming.
Msg 156, Level 15, State 1, Line 14
Incorrect syntax near the keyword 'ON'.
Msg 102, Level 15, State 1, Line 19
Incorrect syntax near 'User_Password'.
Msg 102, Level 15, State 1, Line 29
Incorrect syntax near ')'.
Msg 208, Level 16, State 1, Line 32
Invalid object name 'Content'.
Msg 2714, Level 16, State 6, Line 45
There is already an object named 'ProfileSettings' in the database.
Msg 544, Level 16, State 1, Line 52
'ProfileSettings' when IDENTITY_INSERT is set to OFF.
USE master
GO
if exists ( select * from sysdatabases where name = 'Detour')
drop database Detour
GO
CREATE DATABASE [Detour]
GO
ALTER DATABASE [Detour] SET COMPATIBILITY_LEVEL = 140
GO
SET IDENTITY_INSERT ON [dbo].[orders]
GO
CREATE TABLE dbo.Account (
UserName INT IDENTITY (1,1) PRIMARY KEY
User_Password VARCHAR (20),
GO
INSERT INTO Account(Username, Password) VALUES ('ReedKinney', 'PASSWORD123')
CREATE TABLE Content (
Content_Cycle INT IDENTITY (1,1) PRIMARY KEY,
TV VARCHAR(50),
MOVIES VARCHAR(50),
GENRES VARCHAR(50),
HIGHESTRATED VARCHAR(50)
GO
INSERT INTO Content(GENRES, TV, MOVIES, HIGHESTRATED) VALUES('ACTION', 'THE WITCHER' , 'BLADE
RUNNER', 'SHERLOCK HOLMES')
INSERT INTO Content(GENRES, TV, MOVIES, HIGHESTRATED) VALUES('CLASSICS', 'TWIN PEAKS', 'TAXI
DRIVER', 'THE LONGEST YARD')
INSERT INTO Content(GENRES, TV, MOVIES, HIGHESTRATED) VALUES('COMEDIES', 'THE OFFICE', 'JUST
FRIENDS', 'WATERBOY')
INSERT INTO Content(GENRES, TV, MOVIES, HIGHESTRATED) VALUES('DOCUMENTARIES', 'TIGER KING',
'ICARUS', 'ZEITGEIST')
INSERT INTO Content(GENRES, TV, MOVIES, HIGHESTRATED) VALUES('DRAMAS', 'GAME OF THRONES', 'THE
KINGS SPEECH', 'MARRIAGE STORY')
INSERT INTO Content(GENRES, TV, MOVIES, HIGHESTRATED) VALUES('HORROR', 'HAUNTED MANSION', 'HOUSE
ON THE LEFT', 'PARANORMAL ACTIVITY')
INSERT INTO Content(GENRES, TV, MOVIES, HIGHESTRATED) VALUES('ROMANCE', 'GILMORE GIRLS', 'HER',
'SILVER LNININGS PLAYBOOK')
INSERT INTO Content(GENRES, TV, MOVIES, HIGHESTRATED) VALUES('THRILLER', 'OZARK', 'SE7EN', 'THE
GIRL WITH THE DRAGON TATTOO')
INSERT INTO Content(GENRES, TV, MOVIES, HIGHESTRATED) VALUES('SPORTS', 'BASKETBALL', 'MONEYBALL',
'NACHO LIBRE')
INSERT INTO Content(GENRES, TV, MOVIES, HIGHESTRATED) VALUES('SCIENCE', 'THE UNIVERSE', 'THE
MARTIAN', 'OUR PLANET')
GO
CREATE TABLE ProfileSettings (
ProfileName INT IDENTITY (1,1) PRIMARY KEY,
LanguageChoice VARCHAR(50),
MaturitySetting VARCHAR(50) )
GO
INSERT INTO ProfileSettings (ProfileName, LanguageChoice, MaturitySetting) VALUES('REED',
'ENGLISH', 'ALL CONTENT')
GO
You should use a decent ide such as ssms which would highlight the errors pretty well. I have corrected the syntax errors and annotated the changes in line. If this was an accurate transcription of code I suggest you get another guide.
if exists ( select * from sysobjects where name = 'Detour') --sysdatabases >> sysobjects
drop database Detour
GO
CREATE DATABASE [Detour]
GO
ALTER DATABASE [Detour] SET COMPATIBILITY_LEVEL = 140
GO
SET IDENTITY_INSERT [dbo].[orders] on --move on to end of statement
GO
CREATE TABLE dbo.Account (
UserName INT IDENTITY (1,1) PRIMARY KEY, --
User_Password VARCHAR (20) -- remove ,
) -- added
GO
INSERT INTO Account(Username, USER_Password) VALUES ('ReedKinney', 'PASSWORD123') --password >> user_password
CREATE TABLE Content (
Content_Cycle INT IDENTITY (1,1) PRIMARY KEY,
TV VARCHAR(50),
MOVIES VARCHAR(50),
GENRES VARCHAR(50),
HIGHESTRATED VARCHAR(50)
) --added
GO
INSERT INTO Content(GENRES, TV, MOVIES, HIGHESTRATED) VALUES('ACTION', 'THE WITCHER' , 'BLADE
RUNNER', 'SHERLOCK HOLMES')
INSERT INTO Content(GENRES, TV, MOVIES, HIGHESTRATED) VALUES('CLASSICS', 'TWIN PEAKS', 'TAXI
DRIVER', 'THE LONGEST YARD')
INSERT INTO Content(GENRES, TV, MOVIES, HIGHESTRATED) VALUES('COMEDIES', 'THE OFFICE', 'JUST
FRIENDS', 'WATERBOY')
INSERT INTO Content(GENRES, TV, MOVIES, HIGHESTRATED) VALUES('DOCUMENTARIES', 'TIGER KING',
'ICARUS', 'ZEITGEIST')
INSERT INTO Content(GENRES, TV, MOVIES, HIGHESTRATED) VALUES('DRAMAS', 'GAME OF THRONES', 'THE
KINGS SPEECH', 'MARRIAGE STORY')
INSERT INTO Content(GENRES, TV, MOVIES, HIGHESTRATED) VALUES('HORROR', 'HAUNTED MANSION', 'HOUSE
ON THE LEFT', 'PARANORMAL ACTIVITY')
INSERT INTO Content(GENRES, TV, MOVIES, HIGHESTRATED) VALUES('ROMANCE', 'GILMORE GIRLS', 'HER',
'SILVER LNININGS PLAYBOOK')
INSERT INTO Content(GENRES, TV, MOVIES, HIGHESTRATED) VALUES('THRILLER', 'OZARK', 'SE7EN', 'THE
GIRL WITH THE DRAGON TATTOO')
INSERT INTO Content(GENRES, TV, MOVIES, HIGHESTRATED) VALUES('SPORTS', 'BASKETBALL', 'MONEYBALL',
'NACHO LIBRE')
INSERT INTO Content(GENRES, TV, MOVIES, HIGHESTRATED) VALUES('SCIENCE', 'THE UNIVERSE', 'THE
MARTIAN', 'OUR PLANET')
GO
CREATE TABLE ProfileSettings (
ProfileName INT IDENTITY (1,1) PRIMARY KEY,
LanguageChoice VARCHAR(50),
MaturitySetting VARCHAR(50)
)
GO
INSERT INTO ProfileSettings (ProfileName, LanguageChoice, MaturitySetting) VALUES('REED',
'ENGLISH', 'ALL CONTENT')
GO
Related
I created a SQL stored procedure:
CREATE PROCEDURE [stored procedure name]
(#Location [varchar](255),
#start_date datetime,
#end_date datetime)
AS
BEGIN
SELECT id, location, name, begin_date, age, career, phone_number
FROM information
WHERE [begin_date] BETWEEN #start_date AND #end_date
AND [location] = #Location
END
And there are different groups in location: Shanghai, New York, Toronto, Sydney, Tokyo. But now I would like to have one more category: All. This category will display all locations. So I can use it in SSRS.
What I wrote:
select 1 as sort_order, 'All' as location
union
select distinct 2 as sort_order, location from information
order by sort_order, location
But this will only return a dropdown list of:
"All", "Shanghai", "New York", "Toronto", "Sydney", "Tokyo"
When I click on Shanghai, New York, Toronto, Sydney, Tokyo, it works fine and display corresponding data. But when I click on "All", there is no data showing up. How can I alter my code to achieve the goal?
I think you need to take All into account:
and ([location] = #Location or #location = 'All')
Often, a NULL value is used, to avoid conflict with valid values:
and ([location] = #Location or #location is null)
All:
I am having some problem figuring out how to do cascading parameters with hard coded values.
I have Company that shows the following and these are hard coded parameter values into #Company parameter:
--Select a Company--
Walmart
Target
KMart
When a user selects a company, I need to populate a second parameter, #Site, with hard coded values as well, but the #Site values change depending upon the #Company selected.
All the values are hard coded and none of them come from a database. All the examples I have found show pulling the information from a database.
Would anyone be able to help?
You can simulate a database table.
Create a new datasource if you don't already have one.
I assumed you have values (ID's) and Labels (Company Names) in your 1st parameter and that it is called CompanyID, adjust the following code to suit if not.
Then create a dataset something like this.
DECLARE #t TABLE(CompanyID int, CompanyName varchar(100), Site varchar(100))
INSERT INTO #t
VALUES
(1, 'Walmart', 'Site A'),
(1, 'Walmart', 'Site B'),
(1, 'Walmart', 'Site C'),
(2, 'Target', 'Site 1'),
(2, 'Target', 'Site 2'),
(2, 'Target', 'Site 3'),
(3, 'KMart', 'Site X'),
(3, 'KMart', 'Site Y'),
(3, 'KMart', 'Site Z')
SELECT Site FROM #t WHERE CompanyID = #CompanyID
And don't forget to set your seconds parameter to be multi-value if you want more than one site returning.
there is postgresql database named movie_db, and created a table named films as following:
CREATE TABLE movies (
title varchar(128) NOT NULL,
description varchar(256) NOT NULL,
directors varchar(128)[],
roles varchar(128)[]
);
I want to insert the following data:
title description directors roles
a the love of wind tom tom, kaon, kate
b the second way story john jack, mark
for example, you know the movie has not just one actor, for example, movie has the actor(roles): tom, kaon, and kate. I want to insert these two data into the table using the following command:
insert into movies(title, description, directors, roles) values('a',
'the love of wind', 'tom',{'tom, kano, kate'}))
but there is error:
ERROR: syntax error at or near "{"
LINE 1: ...ors, roles) values('a', 'the love of wind', 'tom',{'tom,
kan..
^
Could you help me to deal with it, thanks for your help!
Thanks#a_horse_with_no_name, I solved it, after I read the document about array in the postgresql document.
The answer about my issue posed:
insert into movies(title, description, directors, roles) values('a',
'the love of wind', '{"tom"}','{"tom", "kano", "kate"}');
I'm just tired by finding out an issue from last more then 5 hours.
I have a table named tblDomains. When I insert a simple record into that table, it inserts a record into another table tblSites also. I don't know how its happening.
There was only one trigger created on table tblDomains. I dropped the trigger and still its inserting a row in another table.
Below is the simple query I'm using to insert records in table tblDomains
INSERT INTO tblDomains(DomainName, CompanyName, Logo,
Address1, Address2, City, State, Zip, Phone, Fax,
tblConfigs_ID, Enabled, tblPricingPlans_ID, ExpireDate, AllowExport,
InactiveDate, tblDomainTypes_ID, ActiveLicenses, AllowPPC, Debitor)
VALUES ('Dname2', 'Cname2', '', 'ad1', 'ad2', 'ct', 'st', '12345678', '21212121211',
'32132132131', 4, '1', 1, null, 0, null, 1, 5, 0, 0);
Can anyone help that how I can track the issue?
I'm not sure what is issue but you can do one this. If possible change the name of tblSites or insert a such values in the tblDomains so that it will throw error while inserting tblSites. I think from error message you may get some clue who is inserting data into tblSites :)
I have several different tables in my database and I'm trying to use Sphinx to do fast full-text searches. For ease of discussion, let's say the main records of interest are packing slips, one of which is included when an order ships. How do I use Sphinx to execute complex queries across all of these tables without completely denormalizing the database?
Each packing slip lists the order number, shipper, recipient, and the tracking number of each box included with the shipment. A separate table contains information about the order items. An additional table contains the customer address information. So, orders contain boxes and boxes contain items. (Example schema listed at the bottom of this question).
I would like to be able to query Sphinx to answers to questions like:
How many people who live on a street named "Maple" ordered an item with "large" in the description?
Which orders contain include the word "blue" in either the box description or order items' description?
To answer these types of questions, I need to refer to several tables. Since Sphinx doesn't have JOINs, one option is to denormalize the database. Denormalizing using a view, so that each row represents an order item--plus all of the data of it's parent box and order, would result in billions of very wide rows. So I've been creating a separate index for each table instead. But that doesn't allow me to query across tables as a SQL JOIN would. Is there another solution?
Example database
CREATE TABLE orders (
id integer PRIMARY KEY,
date_ordered date,
customer_po varchar
);
INSERT INTO orders VALUES (1, '2012-12-13', NULL);
INSERT INTO orders VALUES (2, '2012-12-14', 'DF312442');
CREATE TABLE parties (
id integer PRIMARY KEY,
order_id integer NOT NULL REFERENCES orders(id),
party_type varchar,
company varchar,
city varchar,
state char(2)
);
INSERT INTO parties VALUES (1, 1, 'shipper', 'ACME, Inc.', 'New York', 'NY');
INSERT INTO parties VALUES (2, 1, 'recipient', 'Wylie Coyote Corp.', 'Flagstaff', 'AZ');
INSERT INTO parties VALUES (3, 2, 'shipper', 'Cyberdyne', 'Las Vegas', 'NV');
-- Please disregard the fact that this design permits multiple shippers and multiple recipients
-- per order. This is a vastly simplified version of the system I'm working on.
CREATE TABLE boxes (
id integer PRIMARY KEY,
order_id integer NOT NULL REFERENCES orders(id),
tracking_num varchar NOT NULL,
description varchar NOT NULL,
);
INSERT INTO boxes VALUES (1, 1, '1234567890', 'household goods');
INSERT INTO boxes VALUES (2, 1, '0987654321', 'kitchen appliances');
INSERT INTO boxes VALUES (3, 2, 'ABCDE12345', 'audio equipment');
CREATE TABLE box_contents (
id integer PRIMARY KEY,
order_id integer NOT NULL REFERENCES orders(id),
box integer NOT NULL REFERENCES boxes(id),
qty_units integer,
description varchar
);
INSERT INTO box_contents VALUES (1, 1, 1, 4, 'cookbook');
INSERT INTO box_contents VALUES (2, 1, 1, 2, 'baby bottle');
INSERT INTO box_contents VALUES (3, 1, 2, 1, 'television');
INSERT INTO box_contents VALUES (4, 2, 3, 2, 'lamp');
You put the JOIN in the sql_query that builds the index. The tables remain normalized, but you denormalize when building the index.
Its only a basic example, but your query would be something like.. .
sql_query = SELECT o.id,customer_po,UNIX_TIMESTAMP(date_ordered) AS date_ordered, \
GROUP_CONCAT(DISTINCT party_type) AS party_type, \
GROUP_CONCAT(DISTINCT company) AS company, \
GROUP_CONCAT(DISTINCT city) AS city, \
GROUP_CONCAT(DISTINCT description) AS description \
FROM orders o \
INNER JOIN parties p ON (o.id = p.order_id) \
INNER JOIN box_contents b ON (o.id = b.order_id) \
GROUP BY o.id \
ORDER BY NULL
Update: alternatively can use sql_joined_field to do the same but avoid actual sql_query joins. Sphinx then does the join process for you